@Override
public void onClick(View v) {
ArrayList<Beans> arrs = new ArrayList<Beans>();
Beans b = new Beans();
for (int i = 0; i < 20; i++) {
b.setId(R.drawable.newpro_light);
b.setName("this is title:"+Html.fromHtml("你好!我的<font color=blue>ANDROID</font>之旅!"));
b.setStrs("this.is content!");
arrs.add(b);
}
mListViews.setAdapter(new PopAdapter(RollActivity.this,arrs));
mListViews.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(RollActivity.this,view.getId()+" := "+position,1).show();
}
});
}
});
btns[2].setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ArrayList<Beans> arrs = new ArrayList<Beans>();
Beans b = new Beans();
for (int i = 0; i < 20; i++) {
b.setId(R.drawable.todayspe_light);
b.setName("this is title");
b.setStrs("this.is content!");
arrs.add(b);
}
mListViews.setAdapter(new PopAdapter(RollActivity.this,arrs));
mListViews.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(RollActivity.this,view.getId()+" :> "+position,1).show();
}
});
}
});
}
private void showPopupWindow(View view) {
if(!mPopupWindow.isShowing()){
mPopupWindow.showAsDropDown(view,40, -10);
}
}
LayoutInflater mInflater;
public class PopAdapter extends BaseAdapter{
private Context mContext;
private ArrayList<Beans> arrs;
public PopAdapter(Context c,ArrayList<Beans> arr) {
this.mContext = c;
this.arrs = arr;
}
@Override
public int getCount() {
return arrs.size();
}
@Override
public Object getItem(int position) {
return arrs.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(arrs == null){
return null;
}
if(convertView == null){
PopuView view = new PopuView(mContext);
view.updateView(arrs.get(position));
convertView = view;
}else{
((PopuView)convertView).updateView(arrs.get(position));
}
return convertView;
}
}
public class PopuView extends LinearLayout{
private Context mContext;
public PopuView(Context c) {
super(c);
this.mContext = c;
initialize(c);
}
ImageButton mImgs;
TextView mTv,mTv2;
private void initialize(Context c){
this.mContext = c;
View view = LayoutInflater.from(mContext).inflate(R.layout.popuitems, null);
mTv = (TextView) view.findViewById(R.id.tv);
mImgs = (ImageButton) view.findViewById(R.id.imgs);
mImgs.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(RollActivity.this, "getDatas:"+v.getId(), 1).show();
}
});
mTv2 = (TextView) view.findViewById(R.id.tv2);
addView(view);
}
public void updateView(Beans b){
mImgs.setImageResource(b.getId());
mTv.setText(b.getName());
mTv2.setText(b.getStrs());
}
}
public class Beans{
private int id;
private String name;
private String strs;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getStrs() {
return strs;
}
public void setStrs(String strs) {
this.strs = strs;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public Bitmap setRotate(int resId) {
Matrix mFgMatrix = new Matrix();
Bitmap mFgBitmap = BitmapFactory.decodeResource(getResources(), resId);
mFgMatrix.setRotate(180f);
return mFgBitmap=Bitmap.createBitmap(mFgBitmap, 0, 0,
mFgBitmap.getWidth(), mFgBitmap.getHeight(), mFgMatrix, true);
}
}
<?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="wrap_content"
android:orientation="vertical"
android:id="@+id/layout_main"
android:background="@drawable/clause_bg"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal"
android:clickable="true"
android:background="@drawable/state_btn_pressed"
android:layout_weight="1"
android:id="@+id/btn_0"
>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:src="@drawable/home_light"
>
</ImageView>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="18px"
android:text="主页">
</TextView>
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal"
android:clickable="true"
android:background="@drawable/state_btn_pressed"
android:layout_weight="1"
android:id="@+id/btn_1"
>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:src="@drawable/newpro_light"
>
</ImageView>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000"
android:textSize="18px"
android:text="推介">
</TextView>
</LinearLayout>