Android 如何将按钮添加到自定义适配器?
我正在为我的项目使用。当我尝试将imagebutton添加到布局中时,其他文本变得不可读取。当我单击它们时,不会执行任何操作。如何将按钮添加到此适配器 下面是列表_布局,一切正常Android 如何将按钮添加到自定义适配器?,android,android-layout,android-adapter,android-imagebutton,Android,Android Layout,Android Adapter,Android Imagebutton,我正在为我的项目使用。当我尝试将imagebutton添加到布局中时,其他文本变得不可读取。当我单击它们时,不会执行任何操作。如何将按钮添加到此适配器 下面是列表_布局,一切正常 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_paren
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Isimsiz"
android:id="@+id/Housename"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="2dp"
android:clickable="false"
android:textColor="#241d1d"
android:layout_row="0"
android:layout_column="0"
android:layout_marginRight="2dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Aciklama Yok"
android:id="@+id/Desc"
android:layout_below="@+id/Housename"
android:clickable="false"
android:layout_alignStart="@+id/Housename"
android:textColor="#241d1d"
android:layout_row="1"
android:layout_column="0"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_alignEnd="@+id/Housename" />
</RelativeLayout>
当我添加图像按钮时,除了imagebutton之外,没有任何东西是可点击的
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton"
android:layout_alignTop="@+id/Housename"
android:layout_alignParentEnd="true"
android:layout_alignBottom="@+id/Desc"
android:clickable="true"
android:onClick="berk"
/>
这是我创建适配器的类的一部分
public void processFinish(String s) {
productList = new JsonConverter<Product>().toArrayList(s, Product.class);
BindDictionary<Product> dict = new BindDictionary<Product>();
dict.addStringField(R.id.Housename, new StringExtractor<Product>() {
@Override
public String getStringValue(Product product, int position) {
return product.HouseID;
}
});
dict.addStringField(R.id.Desc, new StringExtractor<Product>() {
@Override
public String getStringValue(Product product, int position) {
return product.Desc;
}
});
FunDapter<Product> adapter = new FunDapter<>(
ListActivity.this, productList, R.layout.layout_list, dict);
lvProduct = (ListView)findViewById(R.id.lvProduct);
lvProduct.setAdapter(adapter);
lvProduct.setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//do sth
}
public void berk(View v) {
//do sth
}
public void processFinish(字符串s){
productList=new JsonConverter().toArrayList(s,Product.class);
BindDictionary dict=新建BindDictionary();
dict.addStringField(R.id.Housename,新StringExtractor(){
@凌驾
公共字符串getStringValue(产品,int位置){
返回产品.HouseID;
}
});
dict.addStringField(R.id.Desc,新StringExtractor(){
@凌驾
公共字符串getStringValue(产品,int位置){
退货产品描述;
}
});
FunDapter适配器=新的FunDapter(
ListActivity.this、productList、R.layout.layout\u list、dict);
lvProduct=(ListView)findViewById(R.id.lvProduct);
lvProduct.setAdapter(适配器);
lvProduct.setOnItemClickListener(this);
}
@凌驾
public void onItemClick(AdapterView父对象、视图、整型位置、长id){
//做某事
}
公共图书馆(视图五){
//做某事
}
注意:当我给xml中的文本赋予clickable属性时,它们也会停止工作。就像我玩布局xml时,所有内容都会停止工作。在适配器类中
public View getView(最终int位置、视图转换视图、视图组父视图){
LayoutInflater充气机=getLayoutInflater();
视图行=充气机。充气(右侧布局。车辆详细信息行,父级,错误);
Button deleteImageView=(Button)row.findViewById(R.id.deleteImageView);
deleteImageView.setOnClickListener(新的OnClickListener(){
公共void onClick(视图v){
//...
}
});
}
但是您可以得到一个问题-listView行不可单击。解决方案:
- 使ListView可聚焦android:focusable=“true”
- 按钮不可聚焦android:focusable=“false”
公共void onClick(视图v){
//... }
});
与Imagebutton类似
除去 android:clickable=“true”
希望有帮助。我制作了softinoutmode并添加了这两行lvProduct.setItemsCanFocus(true);lvProduct.setDegenantFocusability(ViewGroup.FOCUS在子体之前);仍然只有按钮工作列表行不我不明白代码的作用。我没有类似的代码。顺便说一句,我做了2个聚焦解决方案,但没有工作
First of all if u are using button or edit text in your adapter or row file Then every thing will get stop working .
You should use
1.Set descendant Focusablity="before Descendants" in the list view.
2.Set window Soft Input Mode="adjust Pan" in the manifest
3.Set list view.set Items Can Focus(true)