我想改變TEXT按鈕上的按鈕onclicklistener但對於每5行顯示TEXT按鈕相同的結果。我只是想更改文本按鈕1個按鈕點擊的ListView自定義ArrayAdapter - 改變從按鈕TEXT按鈕OnClickListener
XML佈局childview
<Button
android:id="@+id/btn_seatmap"
style="@style/buttonSeatMap"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/txt_kereta_tiba"
android:layout_toRightOf="@+id/txt_info_seat"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="@string/btn_seatmap" />
自定義適配器XML佈局的ListView
<ListView
android:id="@+id/list_kereta"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/btn_pilih_jadwal"
android:layout_below="@+id/txt_title_jadwal_kai"
android:layout_marginBottom="10dp"
android:background="@android:color/white"
android:choiceMode="singleChoice"
android:dividerHeight="1dp"
android:focusable="true"
android:scrollbars="none" />
這裏代碼
@Override
public View getView(final int arg0, View arg1, ViewGroup arg2) {
View view = arg1;
ListHolder listHolder = null;
if (view == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
view = inflater.inflate(layoutResourceId, arg2, false);
listHolder = new ListHolder();
listHolder.layout = (RelativeLayout) view
.findViewById(R.id.layout_jadwal_kai);
listHolder.txtNama = (TextView) view
.findViewById(R.id.txt_nama_kereta);
listHolder.txtBerangkat = (TextView) view
.findViewById(R.id.txt_kereta_brkt);
listHolder.txtHarga = (TextView) view
.findViewById(R.id.txt_harga_kereta);
listHolder.txtTiba = (TextView) view
.findViewById(R.id.txt_kereta_tiba);
listHolder.txtClass = (TextView) view
.findViewById(R.id.txt_kelas_kereta);
listHolder.txtSeat = (TextView) view
.findViewById(R.id.txt_info_seat);
listHolder.btnSeatMap = (Button) view
.findViewById(R.id.btn_seatmap);
CheckSeatOnProgress = false;
view.setTag(listHolder);
} else {
listHolder = (ListHolder) view.getTag();
}
listHolder.btnSeatMap.setTag(listHolder);
listHolder.btnSeatMap.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ListHolder holder = (ListHolder) v.getTag();
holder.btnSeatMap.setText("TEST");
// listHolder.btnSeatMap.setText("TEST");
});
適配器代碼
public void refreshListJadwal() {
adapter = new AdapterListKereta(getActivity(),
R.layout.custom_list_jadwalkai, setGetJadwals, dataJadwalKereta);
listKereta.setAdapter(adapter);
}
「TEST」 顯示,每5行。 請幫忙。如果你想點擊,那麼你可以使用ArrayList後更改按鈕的文字謝謝
郵適配器代碼 – Raghavendra
@Raghavendra我已經更新了我的問題 –
在onclick u能嘗試這樣呢? ((按鈕)v)的.setText( 「TEST」); ? – Raghavendra