我有一個自定義列表視圖,我可以在其中添加儘可能多的元素。所有這些元素都必須打開一個活動(在我的項目中稱爲「編譯」),並使用一些edittext填充。問題是,我實際上並不知道在我的代碼中寫什麼來告訴應用程序在單擊其中一個元素時打開「編譯」活動。如何從自定義ListView開始活動?
//(顯然,每個元素都必須有其相對的信息打開它的編譯活動,例如:。元素「比薩」必須開啓活動,編譯,其中有所有我以前把關於比薩的相關信息)//
感謝支持
這是我爲ListView代碼:
public class Sheet extends Activity {
private static final int DIALOG_ALERT = 10;
ListView list;
ImageView addBtn;
EditText input;
String[] items;
MyListAdapter adapter;
AlertDialog alert;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sheet);
list = (ListView) findViewById(R.id.list);
addBtn = (ImageView) findViewById(R.id.addPlanBtn);
input = new EditText(this);
items = new String[1];
alert = new AlertDialog.Builder(Sheet.this).create();
alert.setTitle("Activity name: ");
alert.setMessage("Type a name for your activity: ");
alert.setView(input);
alert.setButton("add", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
String value = input.getText().toString();
items[items.length - 1] = value;
adapter = new MyListAdapter(Sheet.this, items);
list.setAdapter(adapter);
String[] temp = new String[items.length +1];
for(int i = 0; i< items.length; i++)
temp[i] = items[i];
items = temp;
alert.dismiss();
adapter.notifyDataSetChanged();
}
});
addBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alert.show();
}
});
}
不起作用,實際上它啓動了CompileActivity,但是當我回到我的列表視圖時,我無法回到元素的相對位置CompileActivity – Thozzmass
您是什麼意思?'無法返回到元素的相對CompileActivity' ?怎麼了?一個錯誤? – iTurki
我的意思是我只能去編譯活動一次,我不能回去那裏甚至沒有通過點擊我在列表視圖上創建的項目 – Thozzmass