我想在滚动视图中创建动态图像视图和按钮,所以我想获取动态创建的单击项目的 ID 我怎样才能得到这是我的代码
公共类 TestActivity 扩展 Activity 实现 OnClickListener {
private static final String TAG_DATA="data";
private static final String TAG_ADVERTISE="advertisments";
private static final String TAG_ADVERTISEID="advt_id";
String advertiseid;
private static final String TAG_SHOWTEXT="showtext";
String showtext;
private static final String TAG_PRODUCTINFO="product_info";
String productinfo;
private static final String TAG_THUMBIMAGE="thumbsrc";
String thumbimage;
private static final String TAG_DISTANCE="distance";
String distance;
private static final String TAG_STIPCIATED="stipciated";
String stipciated;
ArrayList<HashMap<String, String>> listadvertise = new ArrayList<HashMap<String,String>>();
ArrayList<HashMap<String, String>> listadvertise1 = new ArrayList<HashMap<String,String>>();
ArrayList<HashMap<String, String>> listadvertise2 = new ArrayList<HashMap<String,String>>();
// Webservice parameter for home advertise
String url;
String fbid;
String latitude;
String longitude;
String passdistance;
String offset;
// Webservice parameter for stipciated advertise
String userid;
String stipciate;
int screenheight;
int screenwidth;
AlertDialog alertDialog;
private ProgressDialog progressDialog;
ImageView imagemenu;
ScrollView scrollView3;
ImageView im;
LinearLayout homelistlayout1;
LinearLayout homelistlayout2;
public static final int img=50000;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.test);
alertDialog = new AlertDialog.Builder(this).create();
DisplayMetrics screensize= new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(screensize);
screenheight=screensize.heightPixels;
screenwidth=screensize.widthPixels;
Log.e("Screen Height","---->"+screenheight);
Log.e("Screen Width ","---->"+screenwidth);
RelativeLayout headerlLayout = (RelativeLayout)findViewById(R.id.headerlayout);
headerlLayout.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,((screenwidth*8)/100)+10));
if(CheckConnection.getInstance(this).isOnline(this))
{
// new HomeAsyncTask().execute("");
}
else
{
alert();
}
imagemenu=(ImageView)findViewById(R.id.imagemenu);
imagemenu.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
Intent i = new Intent(TestActivity.this,HorizontalActivity.class);
startActivity(i);
}
});
scrollView3=(ScrollView)findViewById(R.id.scrollview3);
scrollView3.post(new Runnable() {
public void run()
{
scrollView3.scrollTo(0, 200);
}
});
homelistlayout1=(LinearLayout)findViewById(R.id.homelistlayout1);
homelistlayout1.setPadding(0, 100, 0, 0);
homelistlayout2=(LinearLayout)findViewById(R.id.homelistlayout2);
for(int i=0;i<12;i++)
{
im= new ImageView(TestActivity.this);
im.setLayoutParams(new LinearLayout.LayoutParams(200, 200));
if(i%2==0)
{
im.setImageResource(R.drawable.adv);
im.setId(i);
homelistlayout1=(LinearLayout)findViewById(R.id.homelistlayout1);
homelistlayout1.addView(im);
}
else
{
im.setImageResource(R.drawable.adv2);
im.setId(i);
homelistlayout2=(LinearLayout)findViewById(R.id.homelistlayout2);
homelistlayout2.addView(im);
}
}
im.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
ImageView iv=(ImageView) v;
Log.e("sfas","-->"+iv.getId());
}
});
}
}
public void onClick(View v) {
Log.e("Clicked","----->"+v.getId());
switch (v.getId())
{
case img:
Log.e("Clicked","----->"+v.getId());
break;
default:
break;
}
}
}