ListView项目不可点击...它包含在RelativeView中

时间:2017-01-25 18:10:35

标签: android listview

我认为这不是可点击的,因为被包裹在亲戚视野中......这是我的来源。

Item4.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="wrap_content"
    android:orientation="vertical"
  >

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:clickable="true"
        >

    <VideoView
        android:layout_height="105dip"
        android:focusable="false"
        android:layout_width="150dip"
        android:gravity="top"
        android:id="@+id/VideoView" />

    <TextView android:id="@+id/text"
        android:textSize="16sp"
        android:focusable="false"
        android:paddingLeft="150dip"
        android:textStyle="bold"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/text"
        android:gravity="top"
        />

    </RelativeLayout>

</LinearLayout>

在我的onCreate()

 setContentView(R.layout.activity_listofbetas);
    prestListView = (ListView) findViewById(R.id.listtest);
    prestListView.setClickable(true);
    prestListView.setLongClickable(false);
    prestListView.setOnItemClickListener(new AdapterView.OnItemClickListener()
    {
        @Override
        public void onItemClick(AdapterView<?> adapter, View v, int position,
                                long arg3)
        {
            String value = (String)adapter.getItemAtPosition(position);
            Log.d("CLICKED", "clicked");
            // assuming string and if you want to get the value on click of list item
            // do what you intend to do on click of listview row
        }
    });

如何使用setAdapter和getView ...

填充ListView ..
            mAdapter = new RouteColorActivity.MyCustomAdapter();

            for (int c = 0; c < count; c++) {
                final JSONObject jArr = jObj.getJSONObject(String.valueOf(c));
                db.addBeta(jArr.getString("username"), betaid, jArr.getString("url"), jArr.getString("commentcount"), jArr.getString("length"));
                mAdapter.addItem(jArr.getString("username"), jArr.getString("url"), jArr.getString("commentcount"), jArr.getString("length"));
            }

            prestListView.setAdapter(mAdapter);


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

    System.out.println("getView " + position + " " + convertView);
    RouteColorActivity.ViewHolder holder = null;
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.item4, null);
        holder = new RouteColorActivity.ViewHolder();
     //   holder.imageView = (ImageView) convertView.findViewById(R.id.image);

        holder.textView = (TextView) convertView.findViewById(R.id.text);
        convertView.setTag(holder);
    } else {
        holder = (RouteColorActivity.ViewHolder) convertView.getTag();
    }
    holder.textView.setText(mData.get(position).toString() + " \nComments: " + getCommentCount(position) + "\nLength: " + getLength(position));

    return convertView;
}

}

问题很容易解释,我的列表项不可点击。我只需要一个基本的&#34;点击&#34;登录到控制台以验证这是否有效。我已经处理了可聚焦性问题&#34;它没有做任何事情。我尝试使用onClick @Override,但它也没有用。

0 个答案:

没有答案