2016-04-11 13 views
0

私はアイテムのリストを持っていて、これらのアイテムのそれぞれでフォームを作成したいとします。このフォームは2つのチェックボックスとeditTextで構成されています。たとえば、各商品が倉庫とその数量に含まれているかどうかを知りたいとします。リストビューの各要素が項目の名前、2つのチェックボックス、およびeditTextで構成されているリストビューを使用するために私の問題を解決することを考えています。
問題は、リストビューの唯一の使用は、要素のリストを知っている、私はそれで私の問題を解決する方法ではない(私はアンドロイドの初心者です)です。誰か助けてくれますか?
私の問題を解決する別の方法はありますか?
ありがとう各要素のeditTextとcheckboxのAndroidリストビュー

+0

同様の問題があります。これをチェックしてください>> http://stackoverflow.com/questions/8166497/custom-adapter-for-list-view –

+0

あなたのソリューションはこちら:http://www.webplusandroid.com/creating-listview-with-edittext -and-textwatcher-in-android/ –

答えて

0

cusom ListViewアダプタを実装しようとしてください!これは思っているよりも簡単です!

あなたのリスト内の各項目を表しますでしょうレイアウトを作成する必要があります:まず、次に

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 
<EditText 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Test TEST" /> 

<LinearLayout android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_alignBottom="@id/itemTextView" 
    android:layout_alignParentRight="true"> 
    <CheckBox 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

    <CheckBox 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/doneCheckBox" /> 
</LinearLayout> 

あなたのコード内のcusomアダプタを実装:

public CusomAdapter(Context mainContex, YourItems<SomeItem> someItems) { 
    this.mainContex = mainContex; 
    this.someItems = someItems; 
} 

@Override 
public int getCount() { 
    return someItems.size(); 
} 

@Override 
public Object getItem(int position) { 
    return someItems.get(position); 
} 

@Override 
public long getItemId(int position) { 
    return position; 
} 

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 


    View item = convertView; 
    if (item == null) { 
     item = LayoutInflater.from(mainContex).inflate(R.layout.shoplist_item, null); // your listView layout here! 
    } 

    //fill listView item with your data here! 
    //initiate your check box 
    CheckBox doneCheckBox = (CheckBox)item.findViewById(R.id.doneCheckBox); 

    //add a checkbox listener 
    doneCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { 
    @Override 
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
     if(isChecked){ 
      doneCheckBox.ischecked=true; 
     } 
     else{ 
      doneCheckBox.ischecked=false; 
     } 
    } 
}); 

    return item; 
} 

は、ListViewの要素を追加することを忘れないでくださいあなたのアクティビティレイアウト内に!

+0

これで問題は解決しません。 –

+0

あなたはチェックボックスリスナーなしでTextWatcherを使って解決策を提示しました。 –

関連する問題