android不可点击,android – ListView项目不可点击.为什么?

我有一个使用自定义适配器的ListView,但我不能单击ListView项..

列表视图的活动..

package com.adhamenaya.projects;

import java.util.ArrayList;

import android.app.Activity;

import android.content.Context;

import android.os.AsyncTask;

import android.os.Bundle;

import android.view.LayoutInflater;

import android.view.View;

import android.view.View.OnClickListener;

import android.view.ViewGroup;

import android.widget.BaseAdapter;

import android.widget.Button;

import android.widget.Filter;

import android.widget.Filterable;

import android.widget.ListView;

import android.widget.TextView;

import android.widget.Toast;

import com.adhamenaya.classes.Place;

public class PlacesListActivity extends Activity {

private ArrayList places;

private ArrayList items;

GridviewAdapter mAdapter;

private ListView lvPlaces;

private EfficientAdapter adap;

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.places_list);

lvPlaces = (ListView) this.findViewById(R.id.lvPlaces);

new DowanloadPlaces().execute("");

}

private void bindList(ArrayList places) {

this.places = places;

// Start creating the list view to show articles

items = new ArrayList();

for (int i = 0; i < places.size(); i++) {

items.add(String.valueOf(places.get(i).mName));

}

adap = new EfficientAdapter(this);

adap.notifyDataSetChanged();

lvPlaces.setAdapter(adap);

}

// EfficientAdapter : to make a customized list view item

public class EfficientAdapter extends BaseAdapter implements Filterable {

// The function of inflater to convert objects from XML layout file (i.e. main.xml) to a programmable

LayoutInflater inflater;

Context context;

public EfficientAdapter(Context context) {

inflater = LayoutInflater.from(context);

this.context = context;

}

public int getCount() {

// Get the number of items in the list

return items.size();

}

public Object getItem(int position) {

// To return item from a list in the given position

return items.get(position);

}

public long getItemId(int position) {

// TODO Auto-generated method stub

return 0;

}

public View getView(final int position, View convertView,ViewGroup parent) {

ViewHolder holder;

if (convertView == null) {

convertView = inflater.inflate(R.layout.adaptor_content, null);

holder = new ViewHolder();// Create an object to hold at components in the list view item

holder.textLine = (TextView) convertView.findViewById(R.id.textLine);

holder.buttonLine = (Button) convertView.findViewById(R.id.buttonLine);

holder.buttonLine.setOnClickListener(new OnClickListener() {

private int pos = position;

public void onClick(View v) {

places.remove(pos);

bindList(places);// to bind list items

Toast.makeText(getApplicationContext(),"Deleted successfuly :)", Toast.LENGTH_LONG).show();

}

});

convertView.setTag(holder);

} else {

holder = (ViewHolder) convertView.getTag();

}

// Bind the data efficiently with the holder.

holder.textLine.setText(String.valueOf(places.get(position).mName));

return convertView;

}

public Filter getFilter() {

// TODO Auto-generated method stub

return null;

}

}

// ViewHolder : class that represents a list view items

static class ViewHolder {

TextView textLine;

Button buttonLine;

}

// DownloadRSSFeedsTask: works in a separate thread

private class DowanloadPlaces extends AsyncTask> {

@Override

protected ArrayList doInBackground(String... params) {

ArrayList places = new ArrayList();

Place p = new Place();

for(int i =0;i<25;i++){

p.mName = "Al Mathaf Hotel";

places.add(p);

}

return places;

}

@Override

protected void onPostExecute(ArrayList places) {

bindList(places);

}

}

}

places_list.xml布局

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent">

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:id="@+id/lvPlaces">

adaptor_content.xml布局

android:id="@+id/imageView1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignLeft="@+id/textLine"

android:layout_centerVertical="true"

android:src="@drawable/settings" />

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值