80,359
社区成员
发帖
与我相关
我的任务
分享
public class MainActivity extends ActionBarActivity {
private View mPopMenuView;
private PopupWindow mPopWindow;
private LinearLayout p1;
private LinearLayout p2;
private LinearLayout p3;
private ListView p1List; //屏1的列表
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
setContentView(R.layout.p1);
//getSupportActionBar().setDisplayHomeAsUpEnabled(true); //显示导航的返回按钮
//屏1的列表
try {
p1 = (LinearLayout) LayoutInflater.from(MainActivity.this).inflate(R.layout.p1, null);
if(p1 == null){
Log.e("自定义错误","p1为null");
}else{
Log.e("自定义错误","p1不为null");
}
p1List = (ListView) p1.findViewById(R.id.p1_list);
if(p1List == null){
Log.e("自定义错误","p1List为null");
}else{
Log.e("自定义错误","p1List不为null");
}
BaseAdapter adapter = new BaseAdapter() {
Integer image[] = new Integer[]{R.drawable.dingding, R.drawable.dixi, R.drawable.lala, R.drawable.bo};
String username[] = new String[]{"张三", "李四", "王五", "赵六"};
String message[] = new String[]{"湖南 男 13", "北京 男 14", "广东 男 15", "厦门 男 16"};
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LinearLayout p1ListLayout = null; //屏1列表项布局xml
if (convertView == null) {
p1ListLayout = (LinearLayout) LayoutInflater.from(MainActivity.this).inflate(R.layout.p1_list, null);
} else {
p1ListLayout = (LinearLayout) convertView;
}
ImageView img = (ImageView) p1ListLayout.findViewById(R.id.header_img);
TextView text1 = (TextView) p1ListLayout.findViewById(R.id.username);
TextView text2 = (TextView) p1ListLayout.findViewById(R.id.message);
if(text1 == null){
Log.e("自定义错误","text2为null");
}else{
Log.e("自定义错误","text2不为null");
}
img.setImageResource(image[position]);
text1.setText(username[position]);
text2.setText(message[position]);
return p1ListLayout;
}
@Override
public int getCount() {
return username.length;
}
@Override
public String getItem(int position) {
return username[position];
}
@Override
public long getItemId(int position) {
return position;
}
};
p1List.setAdapter(adapter);
}catch (Exception e){
Log.e("p1List",Log.getStackTraceString(e));
}
}