1
我爲我的列表視圖創建了一個自定義adpater,並創建了我的自定義對話框,其中包含一個列表視圖,但我不知道如何將數據鏈接到自定義列表視圖中對話(即時解釋這個我知道做一個非常糟糕的工作)。我的適配器使用了具有複選框的列表視圖,我想知道如果在下次打開應用程序時檢查或不檢查該如何存儲。 我會把它放在一個步驟,所以它不那麼令人困惑: 我想: 使用我的適配器在我現有的自定義對話框中創建一個列表視圖, 存儲下次打開應用程序時複選框的狀態。使用ListView在自定義對話框中(android)
(其未示出的,但我的列表視圖被稱爲listviewdialog)
我的主要活動(僅顯示自定義對話框位)
button = (Button) findViewById(R.id.button01);
// add button listener
button.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// custom dialog
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.list);
dialog.setTitle("The List");
// set the custom dialog components - text, image and button
TextView text = (TextView) dialog.findViewById(R.id.TextView01);
text.setText("Did you not read the button? :P i'm not finshed on this yet XD");
Button dialogButton = (Button) dialog.findViewById(R.id.Button01);
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
});
我的自定義適配器:
package kevin.erica.box;
import kevin.erica.box.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;
public class MobileArrayAdapter extends ArrayAdapter<String> {
private final Context context;
private final String[] values;
public MobileArrayAdapter(Context context, String[] values) {
super(context, R.layout.list_adapter, values);
this.context = context;
this.values = values;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.list_adapter, parent, false);
CheckBox textView = (CheckBox) rowView.findViewById(R.id.checkBox1);
textView.setText(values[position]);
return rowView;
}
}
然後我將如何將我的數據放到那裏? :) – CarbonAssassin 2012-04-22 17:59:23
最後一件事,它說MobileArrayAdapter無法解析爲mListView.setAdapter(MobileArrayAdapter)中的變量; – CarbonAssassin 2012-04-22 18:05:37
@ user1337110請參閱上面的編輯。至於持久性,儘管如此,你可能更適合創建一個數據庫並使用CursorAdapter進行適配,而不是使用ArrayAdapter – JRaymond 2012-04-22 18:06:22