0

我爲我的項目使用FunDapter。當我嘗試添加imagebutton到我的佈局時,其他文本變得無法點擊。當我點擊它們時什麼都不做。如何將按鈕添加到此適配器?如何將按鈕添加到自定義適配器?

下面是list_layout,一切工作正常

<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 
} 

注意:另外當我給xml中的文本點擊屬性時,他們停止工作。像當我玩佈局XML一切停止工作。

回答

0
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) 
+0

我做了softinoutmode並添加了這兩行lvProduct.setItemsCanFocus(true); lvProduct.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);仍然只有按鈕工作listrows不 – Wardruna

0

在適配器類

public View getView(final int position, View convertView, ViewGroup parent) { LayoutInflater inflater = getLayoutInflater(); View row = inflater.inflate(R.layout.vehicals_details_row, parent, false); Button deleteImageView = (Button) row.findViewById(R.id.DeleteImageView); deleteImageView.setOnClickListener(new OnClickListener() { public void onClick(View v) { //... } }); }

但你可以得到一個問題 - ListView的行不能點擊。解決方案:

  • 化妝的ListView可聚焦機器人:可調焦= 「真」

  • 按鈕不可作爲焦點機器人:可調焦= 「假」

+0

我不明白是什麼代碼does.I沒有simiar code.Btw我做了2個可以專注的解決方案,但沒有工作 – Wardruna

0

你得給個獨立點擊事件的所有意見。

你的ImageButton有android:clickable =「true」,這使得子視圖可點擊。但你其他的觀點是不可點擊的。

解決方案

對於TextView的單擊事件

textView.setOnClickListener(新OnClickListener(){
公共無效的onClick(視圖v){
// ... }
});
爲ImageButton的
類似刪除

機器人:可點擊= 「真」

希望它幫助。

相關問題