Thursday, February 20, 2014

How into a ListActivity from an Activity????


As the title, I transferred to the general Activity method will always be an error
The total run time should be reported ClassNotFoundException, very depressed, novice, seek expert guidance. . . . . . .
I was transferred to an Activity in accordance with the general approach to the operation, is not it wrong? We seek to help, thank you ~ ~ ~ ~ ~

The main program code:
package james.chen;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MyListActivity_01Activity extends Activity {

private Button move_to_list = null;

/ ** Called when the activity is first created. * /
@ Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.main);
move_to_list = (Button) findViewById (R.id.move_to_list);
move_to_list.setOnClickListener (new ToListListener ());
}

class ToListListener implements OnClickListener {
public void onClick (View v) {
Intent intent = new Intent (MyListActivity_01Activity.this, MyListActivity.class);
startActivity (intent);
}
}
}

Here is ListActivity code:

package james.chen;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;
public class MyListActivity extends ListActivity {

ArrayList > list = new ArrayList > ();
HashMap map1 = new HashMap ();
HashMap map2 = new HashMap ();

public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.list);
map1.put ("user_name", "Joe Smith");
map1.put ("user_ip", "192.168.0.1");
map2.put ("user_name", "John Doe");
map2.put ("user_ip", "192.168.0.2");
list.add (map1);
list.add (map2);

SimpleAdapter listAdapter = new SimpleAdapter (this, list,
R.layout.item, new String [] {"user_name", "user_ip"}, new int [] {R.id.user_name, R.id.user_ip});
setListAdapter (listAdapter);
}
}

Here is the configuration file:
1.main.xml


android: orientation = "vertical"
android: layout_width = "fill_parent"
android: layout_height = "fill_parent"
>
android: layout_width = "fill_parent"
android: layout_height = "wrap_content"
android: text = "@ string / hello"
/>

No comments:

Post a Comment