質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Q&A

解決済

1回答

3003閲覧

ボタンとリストビュー

aine

総合スコア12

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

0グッド

0クリップ

投稿2015/10/18 10:23

リストビューとボタンのある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"

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>
</LinearLayout>

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

ListView内にClickableなコンポーネントを組み込むとなかなか処理が大変ですよね.
ListViewのItemのxmlで,親のLayout(RelativeLayout, LinearLayout etc.)に「android:descendantFocusability="blocksDescendants"」を入れると解決することが多いです.(ListViewのこの問題は解決方法がいっぱいあります.)

xml

1<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 android:layout_width="match_parent" 3 android:layout_height="match_parent" 4 android:descendantFocusability="blocksDescendants"> 5 <!-- ボタンなどの要素 --> 6</RelativeLayout>

投稿2015/10/18 10:52

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

aine

2015/10/18 12:35

ありがとうございます。解決出来ました!
退会済みユーザー

退会済みユーザー

2015/10/18 12:36

解決してよかったです.
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問