先 是在 res 文件下面 新建 raw 文件夹 然后 放图片放进去
然后是是 布局 login.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ListView android:id="@+id/login_list" android:layout_width="fill_parent" android:layout_height="wrap_content" android:drawSelectorOnTop="false" android:scrollbars="vertical" ></ListView> </LinearLayout>
然后是 listview 内部 布局的 xml ,java_list.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" android:padding="8dip" > <ImageView android:id="@+id/login_list_left" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" > </ImageView> <TextView android:id="@+id/login_list_right" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" > </TextView> </RelativeLayout>
然后是主 activity ,
package login.mft;
import java.util.ArrayList;
import java.util.HashMap;
import remote.mft.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;
public class LoginIndexActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
ListView list =(ListView)findViewById(R.id.login_list);
//生成冬天数据
ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String,Object>>();
for(int i=0;i<10;i++){
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("ItemImage", R.raw.rdt_right);
map.put("ItemTitle", "Level "+i);
listItem.add(map);
}
SimpleAdapter listItemAdapter = new SimpleAdapter(LoginIndexActivity.this, listItem,
R.layout.login_list,
new String[]{"ItemImage","ItemTitle"},
new int[]{R.id.login_list_left,R.id.login_list_right}
);
list.setAdapter(listItemAdapter);
//添加点击
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
setTitle("点击第"+arg2+"个项目");
}
});
}
}
** 改变 listview 中 某个 键的值
listItem.remove(1); //移除值
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("ItemName", "aa");
map.put("ItemValue", "bb");
map.put("ItemIcon", "cc");
listItem.add(1,map); //添加值
listItemAdapter.notifyDataSetChanged(); //通知更改