0

请帮我。我知道有些人问过这类问题,但我在 stackoverflow 或任何网站上尝试了解决方案,但仍然没有用。问题,我有 listView 并且我想要可点击。似乎 SetOnItemClickListener 没有响应任何内容,logCat 中没有错误,但对于显示,它工作正常。

这是我的代码ActivityAfterLogin.java

public class ActivityAfterLogin extends Activity{


public static final String[] headline = new String[] 
    { 
        "Rattan Craftsmen", "Ceramic Artisans"
    };

public static final String[] goal = new String[] 
    {
        "1,250,000.00",
        "650,000.00"
    };

public static final String[] profitshare = new String[] 
    {
        "8%",
        "9%"
    };

public static final Integer[] images = 
    { 
        R.drawable.bg32, R.drawable.bg60
    };

ListView listView;
List<NewsItem> newsItems;

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_after_login);

    newsItems = new ArrayList<NewsItem>();
    for (int i = 0; i < headline.length; i++) 
    {
        NewsItem item = new NewsItem(images[i], headline[i], goal[i], profitshare[i]);
        newsItems.add(item);
    }


    listView = (ListView) findViewById(R.id.custom_list);
    CustomListAdapter adapter = new CustomListAdapter(this, R.layout.dashboard, newsItems);
    listView.setClickable(true);
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new OnItemClickListener() 
    {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) 
          {

            Intent dashboards = new Intent(view.getContext(), Game.class);
            startActivity(dashboards);

          }

        }); 
}}

这是我的 CustomListAdapter.java 代码

public class CustomListAdapter extends ArrayAdapter<NewsItem>{

//private LayoutInflater layoutInflater;

Context context;

public CustomListAdapter(Context context, int resourceId, List<NewsItem> items) 
{
    super(context, resourceId, items);
    this.context = context;
    //layoutInflater = LayoutInflater.from(context);
}


private class ViewHolder 
{
    ImageView imageView;
    TextView txtHeadline;
    TextView txtGoal;
    TextView txtProfitShare;

}
/*
@Override
public int getCount() {
    return listData.size();
}

@Override
public Object getItem(int position) {
    return listData.get(position);
}

@Override
public long getItemId(int position) {
    return position;
}
*/
public View getView(int position, View convertView, ViewGroup parent) 
{
    ViewHolder holder = null;
    NewsItem newsItem = getItem(position);

    LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

    if (convertView == null) 
    {
        convertView = mInflater.inflate(R.layout.dashboard, null);
        holder = new ViewHolder();
        holder.imageView = (ImageView) convertView.findViewById(R.id.icon);
        holder.txtHeadline = (TextView) convertView.findViewById(R.id.title);
        holder.txtGoal = (TextView) convertView.findViewById(R.id.goal);
        holder.txtProfitShare = (TextView) convertView.findViewById(R.id.profitshare);

        convertView.setTag(holder);


    } 
    else 
    {
        holder = (ViewHolder) convertView.getTag();
    }

    //holder.picturesView.setImageBitmap(newsItem.getUrl());
    holder.imageView.setImageResource(newsItem.getImageId());
    holder.txtHeadline.setText(newsItem.getHeadline());
    holder.txtGoal.setText("Goal: " + newsItem.getGoal());
    holder.txtProfitShare.setText("Profit Share: " + newsItem.getProfitShare());


    return convertView;
}}

这是我的xml代码activity_after_login.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- non-scrolling top pane -->
<!-- navigation bar -->


<!-- scrolling bottom pane -->
<ListView
    android:id="@+id/custom_list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:drawSelectorOnTop="true"
    android:clickable="true"
    android:listSelector="@drawable/list_selector_flatcolor"
    android:divider="#FF0000"
    android:dividerHeight="1dp" />

 </LinearLayout>

这是我的xml代码dashboard.xml

<?xml version="1.0" encoding="utf-8"?>



<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:background="#F7EFEF">


<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:minHeight="60dp"
    android:orientation="horizontal"
    android:padding="7dip" >


        <ImageView
            android:id="@+id/icon"
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:contentDescription="@string/image"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:focusable="false"
            android:clickable="false"
             />

        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/icon"
            android:text=""
            android:textStyle="bold"
            android:typeface="sans"
            android:textSize="16sp"
            android:textColor="@drawable/list_item_text_selector"
            android:focusable="false"
            android:clickable="false" />

        <TextView
            android:id="@+id/goal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/title"
            android:layout_marginTop="10dip"
            android:text=""
            android:textSize="14sp"
            android:textColor="@drawable/list_item_text_selector"
            android:focusable="false"
            android:clickable="false" />

        <TextView
            android:id="@+id/profitshare"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/goal"
            android:layout_alignBottom="@+id/goal"
            android:layout_alignParentRight="true"
            android:text=""
            android:textSize="14sp"
            android:textColor="@drawable/list_item_text_selector"
            android:focusable="false"
            android:clickable="false" />

    </RelativeLayout>
</ScrollView>

对于 Game.class,它只是一个简单的页面 hello world。

如果我删除android:focusableandroid:clickable 帮助我,则没有效果:(

4

0 回答 0