顧客の要求を表示するカスタム ListAdapter があり、各行には 3 つの ImageButtons があり、それぞれ完了、処理中、またはキャンセルのステータスを設定できます。ImageButtons はラジオ ボタンのように機能するように設定されており、1 行に 1 つしかアクティブ化できず、各ボタンには messageID と目的のステータスがタグ付けされています。
ボタンはアクティブ化/非アクティブ化されているため、AppInfo.messageButtons というグローバルに使用可能な Arraylist に追加/削除します。後で ArrayList を繰り返し処理して、どのリクエストが処理され、どのアクションが実行されるべきかを判断します。ボタンを 1 回クリックすると選択でき、もう一度クリックすると選択を解除できます。私の messageButtons 配列リストで何が終わるかという観点からは、この部分はうまく機能しているようです。
私が抱えている問題は、ImageButtons がクリックされずにアクティブ化された状態になることです。実際、アクティブ化した ImageButton ごとに、同じ列のその下にある 6 つおきのボタンが、リンクされているかのようにアクティブ化されます。これは、リクエストの数に関係ありません。私は 6 件のリクエストでそれを実行し、30 件で実行しました。
たとえば、このグラフは、リクエスト 1 を「完了」、リクエスト 3 を「キャンセル」に設定した結果を示しています。2 回クリックするだけで、5 つの項目がアクティブ化されていると表示されます。AppInfo.messageButtons 配列リストには、最初にクリックされた 2 つのみが表示されますが、[Request 7 Completed] を (非アクティブ化するために) もう一度クリックすると、1 と 13 も非アクティブ化されます。
Complete InProcess Cancel
Request 1 X - -
Request 2 - - -
Request 3 - - X
Request 4 - - -
Request 5 - - -
Request 6 - - -
Request 7 X - -
Request 8 - - -
Request 9 - - X
Request 10 - - -
Request 11 - - -
Request 12 - - -
Request 13 X - -
Request 14 - - -
1 つのボタンの onClick ハンドラが 6 行下のボタンをアクティブにする方法を説明できる人はいますか? そして、なぜ6番目のボタンごとに?これは私を困惑させています。
カスタムアダプターのコードは次のとおりです。
public class EloquenceMessageAdapterStaff
extends ArrayAdapter<GlobalMessage>
{
ArrayList<GlobalMessage> roomMessages;
public EloquenceMessageAdapterStaff(Context context, int textViewResourceId, ArrayList<GlobalMessage> roomMessages){
super(context, textViewResourceId, roomMessages);
this.roomMessages = roomMessages;
int count = roomMessages.size();
Log.i("Eloquence","roomMessages adapter count=" + Integer.toString(count) );
}
public View getView(int position, View convertView, ViewGroup parent){
View v = convertView;
if(v == null){
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.messagestaff, null);
}
GlobalMessage md = roomMessages.get(position);
if (md != null) {
int messageId = md.getId();
String messageIdString = Integer.toString(messageId);
String messageText= md.getText();
Date messageTime = md.getInitiatedTime();
PNMCode messagePnm = md.getPnmCode();
String messageFullText = messagePnm.getFullText();
TextView mp_text = (TextView) v.findViewById(R.id.mp_text);
TextView mp_timedate = (TextView) v.findViewById(R.id.mp_timedate);
DateFormat dateformat = new SimpleDateFormat("h:mm a, E d");
String datetext = dateformat.format(messageTime);
if (mp_text != null){
mp_text.setText( messageFullText );
}
if (mp_timedate != null){
mp_timedate.setText( datetext );
}
final ImageButton button_completed = (ImageButton) v.findViewById(R.id.button_messagestatus_Completed);
final ImageButton button_inprocess = (ImageButton) v.findViewById(R.id.button_messagestatus_InProcess);
final ImageButton button_cancel = (ImageButton) v.findViewById(R.id.button_messagestatus_Cancel);
button_completed.setTag(R.id.tag_message_id,messageIdString);
button_completed.setTag(R.id.tag_message_status,"Completed");
button_inprocess.setTag(R.id.tag_message_id,messageIdString);
button_inprocess.setTag(R.id.tag_message_status,"InProcess");
button_cancel.setTag(R.id.tag_message_id,messageIdString);
button_cancel.setTag(R.id.tag_message_status,"Canceled");
button_completed.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
if ( button_completed.isActivated() ) {
AppInfo.messageButtons.remove(button_completed);
button_completed.setActivated(false);
} else {
AppInfo.messageButtons.add(button_completed);
button_completed.setActivated(false);
button_inprocess.setActivated(false);
button_cancel.setActivated(false);
button_completed.setActivated(true);
}
}
});
button_inprocess.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
if ( button_inprocess.isActivated() ) {
AppInfo.messageButtons.remove(button_inprocess);
button_inprocess.setActivated(false);
} else {
AppInfo.messageButtons.add(button_inprocess);
button_completed.setActivated(false);
button_inprocess.setActivated(false);
button_cancel.setActivated(false);
button_inprocess.setActivated(true);
}
}
});
button_cancel.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
if ( button_cancel.isActivated() ) {
AppInfo.messageButtons.remove(button_cancel);
button_cancel.setActivated(false);
} else {
AppInfo.messageButtons.add(button_cancel);
button_completed.setActivated(false);
button_inprocess.setActivated(false);
button_cancel.setActivated(false);
button_cancel.setActivated(true);
}
}
});
}
return v;
}
}
これが私の主なレイアウトです:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
>
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<TextView
android:id="@android:id/empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text=""
/>
</LinearLayout>
ここに私の行のレイアウトがあります:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp"
>
<TextView
android:id="@+id/mp_timedate"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text=""
android:layout_alignParentLeft="true"
/>
<TextView
android:id="@+id/mp_text"
android:layout_width="336dp"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text=""
android:layout_toRightOf="@id/mp_timedate"
/>
<ImageButton android:id="@+id/button_messagestatus_Completed"
style="@style/buttontight"
android:src="@drawable/ic_menu_mark"
android:layout_toRightOf="@id/mp_text"
android:contentDescription="Mark message completed"
/>
<ImageButton android:id="@+id/button_messagestatus_InProcess"
style="@style/buttontight"
android:src="@drawable/ic_menu_stopwatch"
android:layout_toRightOf="@id/button_messagestatus_Completed"
android:contentDescription="Mark message In Process"
/>
<ImageButton android:id="@+id/button_messagestatus_Cancel"
style="@style/buttontight"
android:src="@drawable/ic_menu_block"
android:layout_toRightOf="@id/button_messagestatus_InProcess"
android:contentDescription="Mark message cancelled"
/>
</RelativeLayout>