我在這裏很新,所以我有一個問題..我有這個菜單專門的Listview,我想把一個圖像放在文本之前..這是我的menu2.java ..如何在Android中的ListView中放置圖像和文本
public class menu2 extends Activity {
private ListView listApps;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu2);
listApps = (ListView) findViewById(R.id.listView1);
String str[] = new String[] {"Messaging", "Phone Dialer", "Simple Math", "Splash", "Exit","Quit Application"};
//final ImageView imageView = (ImageView) findViewById(R.id.);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.activity_list_item,android.R.id.text1, str);
listApps.setAdapter(adapter);
listApps.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View aview, int position,
long id){
switch(position){
case 0:
//imageView.setImageResource(R.drawable.ic_launcher);
Intent i1 = new Intent(menu2.this,Messaging.class);
startActivity(i1);
break;
case 1:
Intent i2 = new Intent(menu2.this,PhoneDialer.class);
startActivity(i2);
break;
case 2:
Intent i3 = new Intent(menu2.this,SimpleMath.class);
startActivity(i3);
break;
case 3:
Intent i4 = new Intent(menu2.this,Splash.class);
startActivity(i4);
break;
case 4:
Intent i5 = new Intent(menu2.this,Exit.class);
startActivity(i5);
break;
case 5:
AlertDialog.Builder alt_bld = new AlertDialog.Builder(menu2.this);
alt_bld.setMessage("Are you sure you want to quit application?");
alt_bld.setCancelable(false);
alt_bld.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Action for 'NO' Button
dialog.cancel();
}
});
AlertDialog alert = alt_bld.create();
alert.setTitle("Confirmation");
alert.setIcon(R.drawable.ic_launcher);
alert.show();
}
}
});
}
然後我有我的menu2.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" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
我已經把左邊的形象圖,右邊一個TextView的問題。
只要把他們都在的LinearLayout .. 。 – PearsonArtPhoto
所以我將創造另一個線性佈局?..所以這將是 <的LinearLayout> LinearLayout中> –