リストビューとボタンのあるUIを作っています。
リストビューにアクション(OnItemClick)をつけた所、ボタンが動かなくなり、リストビューも表示がおかしくなりました。
XMLの方は、下記を追加していますが、効果がありません。
android:focusable="false"
android:focusableInTouchMode="false"
お知恵を貸していただけないでしょうか。
public class MainActivity extends Activity {
Intent intent; Intent intent2; private ArrayList<String> savedlist = new ArrayList<String>(); private ArrayList<String> filelist = new ArrayList<String>(); int startservice = 0; String name; ListView listView1; String[] savedList = fileList(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //List listView1 = (ListView) findViewById(R.id.listView1); String[] savedList = fileList(); for (int i = 0; i < savedList.length; i++) { Log.d("filename", savedList[i]); } ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, savedList); listView1.setAdapter(adapter); listView1.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String Filename = listView1.getItemAtPosition(position).toString(); Intent intent2 = new Intent(view.getContext(), MapsActivity.class); intent2.putExtra("Filename", Filename); startActivityForResult(intent, 0); } }); //Button Button button1 = (Button) findViewById(R.id.button1); button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { startLogService(); } }); Button button2 = (Button) findViewById(R.id.button2); button2.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { stopLogService(); } }); } private void startLogService() { startservice = 1; //Create log name Date startdatename = new Date(); name = startdatename.toString(); //Start LogService → GetGps intent = new Intent(MainActivity.this, LogService.class); intent.putExtra("state", "start"); intent.putExtra("name", name); startService(intent); Log.d("Mainactivity", "startLogService"); } private void stopLogService() {//!new if (startservice == 1) { intent = new Intent(MainActivity.this, LogService.class); intent.putExtra("state", "stop"); intent.putExtra("name", name); stopService(intent); //Stop LogService //stopService(new Intent(MainActivity.this,LogService.class)); startservice = 0; Log.d("Mainactivity", "stopLogService"); } }
}
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
</LinearLayout>android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ListView android:layout_height="wrap_content" android:id="@+id/listView1" android:layout_width="match_parent" android:layout_weight="1"/> /> <LinearLayout android:orientation="horizontal" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="center_horizontal"> <Button android:text="Start" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:focusable="false" android:focusableInTouchMode="false" /> <Button android:text="Stop" android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:focusable="false" android:focusableInTouchMode="false" /> </LinearLayout>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/10/18 12:35
退会済みユーザー
2015/10/18 12:36