Actually, I need to make this listview refresh after finishing from another activity. I think I should use either onResume or onStart event to do refresh. Right?
My UI layout looks like Android built-in contact. I use tab activity. my code is below
public class M_G extends TabActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, Weeve.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("w_m_g").setIndicator("Weeve G",
res.getDrawable(R.drawable.ic_tab_artists))
.setContent(intent);
tabHost.addTab(spec);
....
tabHost.setCurrentTab(0);}}
main.xml
<?xml version="1.0" encoding="utf-8"?><TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
</LinearLayout>
Using SampleCursorAdapter, I modified my Weeve class like below - based on Notepad Tutorial idea.
public class Weeve extends Activity{
private String[] lv_arr;
protected ListView CView;
private DBAdapter mDbHelper;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mDbHelper = new DBAdapter(this);
mDbHelper.open();
fillData();}
private void fillData(){
Cursor c = mDbHelper.getAllName();
startManagingCursor(c);
String[] from = new String[] {DBAdapter.WName};
int[] to = new int[] {R.id.txtTabRow};
SimpleCursorAdapter wc = new SimpleCursorAdapter(this,R.layout.tab_row,c,from,to);
setListAdapter(wc);}}
tab_list.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ListView android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/no_wlc"/>
tab_row.xml
<?xml version="1.0" encoding="utf-8"?><TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/txtTabRow"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
I can't see my listview. I got this error below
ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2401
Source not found.
why? how to solve!