#android #android-layout
#Android #android-layout
Вопрос:
в моем приложении я отображаю видео с SD-карты, кнопки с изображением и текстовый вид в виде списка. без кнопок с изображениями в режиме просмотра списка прослушиватель действий работает, но я добавляю кнопки с изображениями в режиме просмотра списка, прослушиватель действий ((тост не отображается)) не работает.
мой xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="100dp"
android:background="#ffffff">
<ImageView
android:src="@drawable/icon"
android:id="@ id/Thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true" />
<LinearLayout android:orientation="vertical"
android:layout_toRightOf="@ id/Thumbnail" android:layout_width="200dp"
android:layout_height="wrap_content" android:id="@ id/textLL"
android:layout_marginLeft="10dp">
<TextView android:layout_width="wrap_content" android:text="fffff"
android:id="@ id/FilePath" android:layout_height="wrap_content"
android:textStyle="bold" android:textSize="25dp"/>
<TextView android:layout_width="wrap_content"
android:text="dskbdskkdsvsvsvvvfff"
android:layout_height="wrap_content" android:id="@ id/title2" />
<LinearLayout android:orientation="horizontal"
android:layout_gravity="center_horizontal" android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageButton android:background="@drawable/play_btn"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="@ id/imageButton2" android:layout_weight="0.5" />
<ImageButton android:background="@drawable/details_btn"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="@ id/imageButton3" android:layout_weight="0.5" />
</LinearLayout>
</LinearLayout>
<ImageButton android:background="@drawable/buy_btn"
android:layout_width="wrap_content" android:layout_height="fill_parent"
android:id="@ id/imageButton1" android:layout_toRightOf="@ id/textLL"/>
если я удалю (кнопки с изображением) следующее из xml, прослушиватель действий (показанный тост) будет работать.
<LinearLayout android:orientation="horizontal"
android:layout_gravity="center_horizontal" android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageButton android:background="@drawable/play_btn"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="@ id/imageButton2" android:layout_weight="0.5" />
<ImageButton android:background="@drawable/details_btn"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="@ id/imageButton3" android:layout_weight="0.5" />
</LinearLayout>
and
<ImageButton android:background="@drawable/buy_btn"
android:layout_width="wrap_content" android:layout_height="fill_parent"
android:id="@ id/imageButton1" android:layout_toRightOf="@ id/textLL"/>
если я добавлю вышеуказанное (ImageButtons) в xml, прослушиватель действий не будет работать, я не знаю, в чем проблема с моим XML-макетом. пожалуйста, помогите мне.
мой код:
public class AndroidThumbnailList extends ListActivity{
..........
public class MyThumbnaildapter extends ArrayAdapter<String>{
public MyThumbnaildapter(Context context, int textViewResourceId,String[] objects) {
super(context, textViewResourceId, objects);
// TODO Auto-generated constructor stub
}
public View getView(int position, View convertView, ViewGroup parent) {
.........
}
}
protected void onListItemClick(ListView l, View v, int position, long id) {
Log.e("video", "called");
String selection = l.getItemAtPosition(position).toString();
Toast.makeText(getBaseContext(), selection, Toast.LENGTH_SHORT).show();
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
_contentUri = MEDIA_EXTERNAL_CONTENT_URI;
initVideosId();
setListAdapter(new MyThumbnaildapter(AndroidThumbnailList.this, R.layout.row, _videosId));
}
}
Ответ №1:
Добавьте android:focusable=»false» в ImageButton. Затем добавьте android:descendantFocusability=»blocksDescendants» в родительский вид ImageButton. В вашем xml есть LinearLayout и RelativeLayout.
Комментарии:
1. спасибо, ваш код работает (отображается всплывающее окно). как я могу написать отдельное действие для каждой кнопки изображения в защищенном пустом onListItemClick (ListView l, View v, int position, длинный идентификатор) { ………… } пожалуйста, помогите мне.