Why does my listview only respond when it's text is clicked?

时间:2016-02-12 21:01:52

标签: java android xml listview

I have a custom listview. The problem is, however, the only part of the listview that is clickable is the text (nowhere to the right/ empty space). I have also added some of my java code.

This is the xml file I use in the arrayAdapter:

URI uri = AnalysisEngine.class.getResource("/models/10_NB_7dev_2.model").toURI();
Path path = Paths.get(uri);

MainActivity.java

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

<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/text"
    android:maxLines="1"
    android:ellipsize="end"
android:textSize="50sp">

</TextView>

3 个答案:

答案 0 :(得分:1)

To react to selections in the list, set an <input class="myButton" type="button" onclick="getLocation();" value="Login"> to your OnItemClickListener. like below, for more about ListView

ListView

答案 1 :(得分:0)

Hi you can use onItemclicklistener and if you look alternate solution then you can click on main layout on adapter.

listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) {

} });

答案 2 :(得分:0)

将TextView宽度设置为match_parent