ボタンクリックでページジャンプを実現
4668 ワード
( ), , ListView
1.xml
2. ( )
package com.dujinlong.listview; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void click(View view) { Intent intent = new Intent(); intent.setClass(MainActivity.this,ListViewLoader.class); startActivity(intent); } }
package com.dujinlong.listview; public class ListViewLoader extends ListActivity implements LoaderManager.LoaderCallbacks
{ // SimpleCursorAdapter mAdapter; // static final String[] PROJECTION = new String[] { ContactsContract.Data._ID, ContactsContract.Data.DISPLAY_NAME }; // static final String SELECTION = "((" + ContactsContract.Data.DISPLAY_NAME + " NOTNULL) AND (" + ContactsContract.Data.DISPLAY_NAME + " != '' ))"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // ProgressBar progressBar = new ProgressBar(this); progressBar.setLayoutParams( new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); progressBar.setIndeterminate(true); getListView().setEmptyView(progressBar); // ViewGroup root = (ViewGroup) findViewById(android.R.id.content); root.addView(progressBar); // String[] fromColumns = { ContactsContract.Data.DISPLAY_NAME }; int[] toViews = { android.R.id.text1 }; // simple_list_item_1 TextView // // null cursor, onLoadFinished() mAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, null, fromColumns, toViews, 0); setListAdapter(mAdapter); // 。 , 。 getLoaderManager().initLoader(0, null,this); } // public Loader onCreateLoader(int id, Bundle args) { // CursorLoad, Cursor return new CursorLoader(this, ContactsContract.Data.CONTENT_URI, PROJECTION, SELECTION, null, null); } // public void onLoadFinished(Loader loader, Cursor data) { // cursor。( , cursor) mAdapter.swapCursor(data); } // , public void onLoaderReset(Loader loader) { // onLoadFinished() Cursor 。 。 mAdapter.swapCursor(null); } @Override public void onListItemClick(ListView l, View v, int position, long id) { // Toast.makeText(getApplicationContext(), " ",0).show(); } } :