0

私を助けてください。一部の人々がこの種の質問をしたことは知っていますが、stackoverflow または任意の Web サイトで解決策を試しましたが、まだ機能しませんでした。問題、私は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:focusableしても効果はありませandroid:clickable ん。助けてください:(

4

0 に答える 0