我創建了兩個對話框,第一個打開第二個對話框,它將訪問列表視圖,第二個對話框在列表視圖中選擇特定項目並將該項目傳輸到第一次對話......我搞砸了我的邏輯,我該怎麼做?無法將列表視圖選中的項目傳遞給textview
這裏的第一個對話框:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.add_students_dialog);
imb1=(ImageButton)findViewById(R.id.im1);
imb2=(ImageButton)findViewById(R.id.im2);
imb3=(ImageButton)findViewById(R.id.im3);
text1=(TextView)findViewById(R.id.Text1);
text2=(TextView)findViewById(R.id.Text2);
text3=(TextView)findViewById(R.id.Text3);
/* Get values from Intent */
Intent intent = getIntent();
String name = intent.getStringExtra("Title1");
text1.setText(name);
ie1=(EditText)findViewById(R.id.edit1);
ib=(Button)findViewById(R.id.dialog_button_cancel);
ib1=(Button)findViewById(R.id.dialog_button_ok);
ib.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent=new Intent(InsertStudent.this, StudentsActivity.class);
startActivity(intent);
}
});
ib1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
String data1 = ie1.getText().toString();
String data2 = ie2.getText().toString();
mySQLiteAdapter.insertSchool(data1, data2);
updateList();
Intent myIntent = new Intent(InsertStudent.this, StudentsActivity.class);
startActivity(myIntent);
}
});
imb1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent myIntent = new Intent(InsertStudent.this, Add1.class);
myIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(myIntent);
}
});
imb2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent myIntent = new Intent(InsertStudent.this, Add2.class);
startActivity(myIntent);
}
});
imb3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent myIntent = new Intent(InsertStudent.this, Add3.class);
startActivity(myIntent);
}
});
}
private void updateList(){
cursor.requery();
}
}
這裏的第二個對話框:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.a_add_class_students);
listContent = (ListView)findViewById(R.id.listView1);
mySQLiteAdapter = new Database(this);
mySQLiteAdapter.openToWrite();
cursor = mySQLiteAdapter.queueSchoolAll();
button1 = (Button) findViewById(R.id.Button01);
button2 = (Button) findViewById(R.id.dialog_button_ok);
// Capture button clicks
button1.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
Intent myIntent = new Intent(Add1.this, InsertSubject.class);
startActivity(myIntent);
}
});
cursor.requery();
String[] from = new String[]{Database.KEY_ID2, Database.KSCHOOL, Database.KSCHOOLCODE};
int[] to = new int[]{R.id.rid, R.id.rt1, R.id.rt2};
cursorAdapter =
new SimpleCursorAdapter(this, R.layout.row_school, cursor, from, to);
listContent.setAdapter(cursorAdapter);
listContent.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
Cursor cursor = (Cursor) arg0.getItemAtPosition(arg2);
final int item_id = cursor.getInt(cursor.getColumnIndex(Database.KEY_ID2));
sdid.sdid(item_id);
Intent intent=new Intent(Add1.this,DetailsSchool.class);
startActivity(intent);
}
});
cursor.requery();
listContent.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
Cursor cursor = (Cursor) arg0.getItemAtPosition(arg2);
final int item_id = cursor.getInt(cursor.getColumnIndex(Database.KSCHOOLCODE));
Intent intent = new Intent(getApplicationContext(),InsertStudent.class);
intent.putExtra("Title1", item_id);
startActivity(intent);
}
});
cursor.requery();
}
private void updateList(){
cursor.requery();
}
}
你爲什麼不能交上來?有一些「例外」嗎?如果是這樣,發佈日誌或您的輸出和例外輸出。 –
它只是發生,只要我在列表視圖上選擇特定的項目textview保持空...我真的沒有任何想法,theres沒有錯誤 – CJanon
對話框在哪裏?我看到新的意圖得到調用:( –