私はjsonの解析でデータを満たすリストビューを作成しています。私はCustomviewをCustomViewで使用しています。条件に合わせてtextviewsをlistviewに設定しています。私の要件は、listviewの行をクリックしたときに、リストビューで、しかし、問題は、私はitem.SoのIDを取得するunnableといういずれかが、私はあなたがたときにイベントを登録しようとしている場合、これはlistviewの特定の行をクリックしてtextviewのIDを取得できませんでしたか?
public View getView(final int position, View convertView,
ViewGroup parent) {
// TODO Auto-generated method stub
final MyVoucherOffer voucherOffer = (MyVoucherOffer) voucherListAdapter
.get(position); // Remove offer
LayoutInflater inflater = (LayoutInflater) VoucherActiveScreen.this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
getIs_bidding = voucherOffer.getIs_bidding();
Log.i("==getIs_bidding==", getIs_bidding);
getResale_price = voucherOffer.getResale_price();
Log.i("==getResale_price==", getResale_price);
/*if (listType == 3) {
convertView = inflater.inflate(R.layout.voucher_inactive_list,
null);
} else if(listType == 1){
convertView = inflater.inflate(R.layout.voucher_active_list,
null);
}else if(listType == 2){
convertView = inflater.inflate(R.layout.bidding_list, null);
}*/
//Code Added
if (listType == 3) {
convertView = inflater.inflate(R.layout.voucher_inactive_list,
null);
} else{
convertView = inflater.inflate(R.layout.voucher_active_list,
null);
}
//
// 1. offerTitle-
// 2. offerPricce
// 3. star
// 4. offerDiscription
// 5. condition
// 6. number
ProgressBar progress = (ProgressBar) convertView
.findViewById(R.id.progressBar1);
RelativeLayout mylayout = (RelativeLayout) convertView
.findViewById(R.id.mylayoutV);
ImageView dealImage1 = (ImageView) convertView
.findViewById(R.id.dealImageV);
ImageView birds = (ImageView) convertView
.findViewById(R.id.birds);
int z = position % 2;
if (z == 1) {
mylayout.setBackgroundResource(R.drawable.dark_gray);
}
ArrayList<String> al = voucherOffer.getImageOffer();
if (al.size() > 0) {
String url = al.get(0).toString();
url = "http://bma.in/ian_watt/application/views/scripts/vendor/uploads/"
+ url;
try {
dealImage1.setTag(url);
imageloader.DisplayImageLoader(url, VoucherActiveScreen.this,
dealImage1,progress);
} catch (Exception e) {
// TODO: handle exception
Log.e("error", e.getMessage().toString());
}
} else {
dealImage1.setImageResource(R.drawable.no_img);
}
ImageButton arrow = (ImageButton) convertView
.findViewById(R.id.list_arrowV);
TextView offerTitle = (TextView) convertView
.findViewById(R.id.offerTitleV);
offerTitle.setText(voucherOffer.getFld_name());
TextView offerPrice = (TextView) convertView
.findViewById(R.id.offerPriceV);
offerTitle.setTypeface(font_bold);
// offerTitle.setText(localMapOffer.getOffer_price()));number
Log.v("", voucherOffer.getOffer_price());
try {
double op = Double.parseDouble(voucherOffer.getOffer_price());
double cp = Double
.parseDouble(voucherOffer.getCustomer_price());
if (listType == 3)
{
if (voucherOffer.getIs_redeem().toString().equals("1")
|| voucherOffer.getIs_redeem().toString() == "1") {
offerPrice.setTypeface(font_bold);
offerPrice.setText("Rate");
} else {
offerPrice.setTypeface(font);
offerPrice.setText("View");
}
} else {
if (op - cp == 0.0) {
offerPrice.setText("Free");
} else {
offerPrice.setText("$" + voucherOffer.getOffer_price());
}
}
} catch (Exception e) {
// TODO: handle exception
Log.e("error", e.getMessage().toString());
}
if (listType == 3)
{
TextView star = (TextView) convertView
.findViewById(R.id.starVText);
star.setTypeface(font_bold);
Log.e("!!!!!!!!!! VoucherActive", " V :: "
+ voucherOffer.getIs_redeem().toString());
if (voucherOffer.getIs_redeem().toString().equals("1")
|| voucherOffer.getIs_redeem().toString() == "1") {
star.setText("Redeemed "
+ getStringDate(voucherOffer.getModified()
.toString()));
} else if (voucherOffer.getIs_sold().toString().equals("1")
|| voucherOffer.getIs_sold().toString() == "1") {
star.setText("Sold "
+ getStringDate(voucherOffer.getModified()
.toString()));
} else if (voucherOffer.getIs_expired().toString().equals("1")
|| voucherOffer.getIs_expired().toString() == "1") {
star.setText("Expired "
+ getStringDate(voucherOffer.getModified()
.toString()));
}
} else {
if(voucherOffer.getIs_bidding().equalsIgnoreCase("1"))
birds.setVisibility(View.VISIBLE);
ImageView star = (ImageView) convertView
.findViewById(R.id.starV);
hm = Data.getValue(hm);
Log.v(",val", voucherOffer.getFld_rating() + "");
if (hm.containsKey(voucherOffer.getFld_rating())) {
star.setImageResource(hm.get(voucherOffer.getFld_rating()));
}
/*else if(voucherOffer.getIs_bidding().equalsIgnoreCase("0") && voucherOffer.getResale_price().equalsIgnoreCase("0.00")){
}*/
}
TextView offerDiscription = (TextView) convertView
.findViewById(R.id.discriptionV);
offerDiscription.setText(voucherOffer.getOffer_title());
offerDiscription.setTypeface(font);
TextView dayV = (TextView) convertView.findViewById(R.id.dayV);
TextView distance = (TextView) convertView
.findViewById(R.id.distacneV);
if (listType == 3) {
if (voucherOffer.getIs_redeem().toString().equals("1")
|| voucherOffer.getIs_redeem().toString() == "1") {
distance.setTypeface(font_bold);
distance.setText("This");
} else {
distance.setTypeface(font);
distance.setText("Voucher");
}
} else {
distance.setTypeface(font);
if (voucherOffer.getDistance().length() > 5) {
distance.setText(voucherOffer.getDistance().substring(0, 4)
+ "m");
} else {
distance.setText(voucherOffer.getDistance() + "m");
}
}
try {
DateFormat df = new SimpleDateFormat("MM/dd/yy");
Date today = df.parse(voucherOffer.getOffer_enddate());
Log.v("today", today.toString());
long endDate = today.getTime();
Calendar currentDate = Calendar.getInstance();
long current = currentDate.getTimeInMillis();
Log.v("current milis", "" + current);
long cal = endDate - current;
if (listType == 3) {
if (voucherOffer.getIs_redeem().toString().equals("1")
|| voucherOffer.getIs_redeem().toString() == "1") {
dayV.setTypeface(font_bold);
dayV.setText("Deal");
} else {
dayV.setTypeface(font);
dayV.setText("Page");
}
} else {
dayV.setTypeface(font);
dayV.setText(getDay(cal));
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
mylayout.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
try {
---------------------my problem section----------------------------
if (listType == 1) {
Log.v("active", "On Click " + (position));
if(Integer.parseInt(ParsingData.is_bid) == 1 && Integer.parseInt(ParsingData.is_resale) == 0){
System.out.println("inside first case");
Intent intent = new Intent(
VoucherActiveScreen.this,
MyVoucherDetailPage.class);
intent.putExtra("selectedIndex", position);
intent.putExtra("listType", listType);
intent.putExtra("isPurchasedVoucher ", false);
startActivity(intent);
}
else{
System.out.println("inside else case");
Intent intent = new Intent(
VoucherActiveScreen.this,
MyVoucherDetailPage.class);
intent.putExtra("selectedIndex", position);
intent.putExtra("isPurchasedVoucher ", true);
intent.putExtra("listType", listType);
startActivity(intent);
------------------------end----------------------------
}
}
//Code Added
/*else if(listType == 2){
Log.v("Bidding", "On Click " + (position));
Intent intent = new Intent(VoucherActiveScreen.this,
MyVoucherDetailPage.class);
intent.putExtra("selectedIndex", position);
intent.putExtra("listType", listType);
startActivity(intent);
}*/else if (listType == 3) {
Intent intent = new Intent(
VoucherActiveScreen.this,
MyVoucherDetailPage.class);
intent.putExtra("listType", listType);
intent.putExtra("selectedIndex", position);
Log.v("inactive", "On Click " + (position));
startActivity(intent);
}
} catch (Exception e) {
// TODO: handle exception
}
}
});
return convertView;
}
リストビューの行をクリックすると、onListItemClickが呼び出されます。最後のパラメータは、ドキュメントにあるクリックされた行のIDです。 – Blackbelt