中的另一個活動中使用任何其他佈局的組件(除setContentView()中定義的)我正在處理一個應用程序,在該應用程序中我需要在listview中爲我創建的一些數據一個與包含listview的佈局相關的活動,用於創建自定義listitem的listview。現在我需要從活動中的自定義列表項訪問組件(Imageview)。任何人都可以請告訴我如何實現這一目標?我如何在android
這是活動
package com.example.manishnegi.sharemyride;
public class RideMatched extends Activity {
int commentCount = 0;
private List<GetRidesSummaryDetails> oslist = new ArrayList<GetRidesSummaryDetails>();
ListView rides_matchedListview;
ImageView hrate1,hrate2,hrate3,hrate4,hrate5;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ride_matched);
hrate1=(ImageView)findViewById(R.id.hrate1);
hrate2=(ImageView)findViewById(R.id.hrate2);
hrate3=(ImageView)findViewById(R.id.hrate3);
hrate4=(ImageView)findViewById(R.id.hrate4);
hrate5=(ImageView)findViewById(R.id.hrate5);
int l=0;
String arr;
JSONArray array=new JSONArray();
Bundle b=getIntent().getExtras();
if(b!=null)
{
l=b.getInt("array_length");
arr=b.getString("rides_array");
try {
array=new JSONArray(arr);
Log.e("String to array ",array.toString());
} catch (JSONException e) {
e.printStackTrace();
Log.e("String to array",e.getMessage());
}
Log.e("Number of matched",l+"");
}
rides_matchedListview = (ListView)findViewById(R.id.rides_matchedListview);
Second scnd = new Second();
List<GetRidesSummaryDetails> detailsofrides = scnd.getallcomments(l,array);
for (GetRidesSummaryDetails values :detailsofrides){
String driver_imageget = values.getDriverimage();
String driver_nameget = values.getDrivername();
String pickup_get = values.getPickuptime();
String ride_idget= values.getRideId();
String rating_get = values.getRating();
String vehicle_imageget = values.getVehicleImage();
GetRidesSummaryDetails vehi = new GetRidesSummaryDetails();
vehi.setDriverimage(driver_imageget);
vehi.setDrivername(driver_nameget);
vehi.setPickuptime(pickup_get);
vehi.setRideId(ride_idget);
vehi.setRating(rating_get);
setRating(Integer.parseInt(rating_get));
vehi.setVehicleImage(vehicle_imageget);
oslist.add(vehi);
commentCount++;
rides_matchedListview.setAdapter(new RidesMatchedAdapter(RideMatched.this, 0, oslist));
new RidesMatchedAdapter(RideMatched.this ,0, oslist).notifyDataSetChanged();
}
}
public void setRating(int rate)
{
if (rate == 1) {
hrate1.setImageResource(R.drawable.star);
}
if (rate == 2) {
hrate1.setImageResource(R.drawable.star);
hrate2.setImageResource(R.drawable.star);
}
if (rate == 3) {
hrate1.setImageResource(R.drawable.star);
hrate2.setImageResource(R.drawable.star);
hrate3.setImageResource(R.drawable.star);
}
if (rate == 4) {
hrate1.setImageResource(R.drawable.star);
hrate2.setImageResource(R.drawable.star);
hrate3.setImageResource(R.drawable.star);
hrate4.setImageResource(R.drawable.star);
}
if (rate == 5) {
hrate1.setImageResource(R.drawable.star);
hrate2.setImageResource(R.drawable.star);
hrate3.setImageResource(R.drawable.star);
hrate4.setImageResource(R.drawable.star);
hrate5.setImageResource(R.drawable.star);
}
}
}
這是列表視圖佈局(ride_matched.xml)
這是自定義列表項
你可以請你發佈你的代碼? –
當你點擊它時你想訪問那個子視圖(列表項)嗎? –
我已經添加了所需的代碼和圖像,現在可以請你幫忙 – Brucode