我是Android編程中的新成員,我希望構建一個數字校園計劃。爲此,我使用了一些活動。我想要創建一個計劃並在ListView中列出,用戶可以在此控件上的ListView中單擊並查看所有Homeworks等等。如何在Android中填充我的ListView
這裏是我的想法:
我打造爲CreateMain一個活動:
public void createPlan(View view)
{
String PlanName;
Intent intent = new Intent(this,ListenActivity.class);
EditText planName = (EditText)findViewById(R.id.editText1);
PlanName = planName.getText().toString();
intent.putExtra(ListViewMessage, PlanName);
startActivity(intent);
}
而對於秀活動的創建數據在ListView
import android.os.Bundle;
import android.view.Menu;
import java.util.List;
import android.app.ListActivity;
import android.widget.ArrayAdapter;
public class ListenActivity extends ListActivity {
private CommentsDataSource datasource;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_open);
datasource = new CommentsDataSource(this);
datasource.open();
List<Comment> values = datasource.getAllComments();
// Use the SimpleCursorAdapter to show the
// elements in a ListView
ArrayAdapter<Comment> adapter = new ArrayAdapter<Comment>(this,
android.R.layout.simple_list_item_1, values);
setListAdapter(adapter);
Comment comment = null;
String[] comments = new String[] { "t1", "t2", "t3" };
comment = datasource.createComment(comments[1]);
adapter.add(comment);
adapter.notifyDataSetChanged();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_list, menu);
return true;
}
}
但我不知道如何使用此前的活動數據在我的ListView中的活動。我想用一個SQLite數據庫,但它不工作:(
讓我看看我是否理解你。你想通過SQLite傳遞數據嗎? –
是的我希望我可以添加一個ListView行 – Tarasov