你好
我正在尝试在列表视图中启动一项活动 onclick
- 我为此使用 Bean 类(Names.java)
- 这是我的课
名称.java
public class Names implements Serializable{
private String Name;
public void setName(String name){
this.Name=name;
}
public String getName(){
return Name;
}
}
新配置文件.java
public class NewProfile extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.new_profile);
Bundle b=getIntent().getExtras();
TextView tv=(TextView) findViewById(R.id.NewTextView);
}
}
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/listView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1" >
</ListView>
</LinearLayout>
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="5dp"
android:text="TextView"
android:textStyle="italic|bold" />
</LinearLayout>
new_profile.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/NewTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="TextView"
android:textSize="18dp"
android:textStyle="bold" />
</RelativeLayout>
MainActivity.java
public class MainActivity extends Activity implements OnItemClickListener {
ArrayList<Names> AL=new ArrayList<Names>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Names obj1=new Names();
obj1.setName("Sam");
AL.add(obj1);
Names obj2=new Names();
obj2.setName("carl");
AL.add(obj2);
ListView LV=(ListView) findViewById(R.id.listView1);
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,R.layout.list_item,R.id.textView1,AL);
LV.setAdapter(adapter);
LV.setOnItemClickListener(this);
}
public void onItemClick(AdapterView<?> arg0, View v, int position, long arg3) {
// TODO Auto-generated method stub
Bundle B=new Bundle();
TextView TV=(TextView) findViewById(R.id.textView1);
if(position==0){
}
}
}
MainActivity 类不完整......我正在尝试填充这个类的部分
有任何想法吗,
谢谢