嗨我需要在列表視圖行中的活動按鈕的幫助。想法然後我按下按鈕,它改變了textview的行。此列表行必須在中激活setOnItemLongClickListener(); 任何人都可以告訴我的例子或教程如何使這樣的事情或一些例子或顯示有我的問題?我厭倦了谷歌它,並不會得到答案...我新的Android和抱歉我的語言和TNX的任何幫助;) 我的想法。Android列表查看與更改行中的文本的活動按鈕
+-----------------------------------------+
| textview | textview | textview | Button |
+----------+----------+----------+--------+
| textview | textview | textview | Button |
+-----------------------------------------+
然後按下按鈕的TextView成爲數是這樣的:
+-----------------------------------------+
| textview | textview | textview | Button |
+----------+----------+----------+--------+
| textview | textview | 1 | Button | <- this button was pressed
+-----------------------------------------+
我做了按鈕,然後改變它,但問題是,它改變更多的行。像
+-----------------------------------------+
| textview | textview | textview | Button |
+----------+----------+----------+--------+
| textview | textview | 1 | Button | <- this button was pressed
+-----------------------------------------+
| textview | textview | textview | Button |
+----------+----------+----------+--------+
| textview | textview | 1 | Button | <- this button was **not** pressed
+----------+----------+----------+--------+
| textview | textview | textview | Button |
+----------+----------+----------+--------+
| textview | textview | 1 | Button | <- this button was **not** pressed
+-----------------------------------------+
我正在使用SimpleAdapter獲取列表。
ListView lv = getListView();
lv.setOnItemLongClickListener(listener);
OnItemLongClickListener listener = new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> parent, final View view, int position, long id) {
btn1 = (Button) view.findViewById(R.id.button1);
btn1.setOnClickListener(new OnClickListener(){
int number= 0;
public void onClick(View v) {
// TODO Auto-generated method stub
TextView textView = (TextView) v.findViewById(R.id.textView_must_be_changed);
number++;
textView.setText(String.valueOf(number));
}
});
}
};
我的佈局XML是
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:id="@+id/gridas"
android:layout_height="fill_parent"
android:choiceMode="multipleChoice"
android:columnCount="10"
android:descendantFocusability="beforeDescendants" >
<TextView
android:id="@+id/Textview"
android:layout_column="5"
android:layout_columnSpan="3"
android:layout_gravity="left|bottom"
android:layout_row="1"
android:layout_rowSpan="2"
android:text="4.3 kg" />
<TextView
android:id="@+id/Textview"
android:layout_column="7"
android:layout_gravity="left"
android:layout_row="1"
android:layout_rowSpan="2"
android:text="35 cm" />
<TextView
android:id="@+id/Textview"
android:layout_width="163dp"
android:layout_height="49dp"
android:layout_column="9"
android:layout_gravity="left"
android:layout_row="2"
android:gravity="left"
android:text="949.00 Lt"
android:textSize="32sp"
android:textStyle="bold" />
<TextView
android:id="@+id/**textView_must_be_changed**"
android:layout_column="9"
android:layout_gravity="left|top"
android:layout_row="1"
android:text="tekstukas"
/>
<Button
android:id="@+id/button1"
android:layout_column="9"
android:layout_gravity="left|top"
android:layout_row="3"
android:text="Button"
android:focusable="false"
android:focusableInTouchMode="false"/>
</GridLayout>
感謝您的幫助;) 但請告訴我更多;)所以,如果我想做出同樣的清單,那麼我必須採取SimpleAdapter源代碼並複製tu我的CustomAdapter並將getView更改爲像這樣的東西,但只是爲了我的佈局? http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/1.5_r4/android/widget/SimpleAdapter.java – 2013-02-20 13:50:49
恰好不是:)您應該擴展自定義適配器public CustomAdapter(上下文上下文,List dataList)super(上下文,R.layout.row_layout,R.id.key_id,dataList);類定製適配器擴展ArrayAdapter } @Override public View getView(int position,View convertView,ViewGroup parent){// ...} ' –
rdbmsa
2013-02-20 15:42:56