Ich habe eine Listenansicht erstellt, die automatisch ihren Inhalt von einer SQL DB erstellt. Wenn Sie darauf klicken, wird jedes Listenelement basierend auf dem Klick auf eine andere Seite geöffnet, aber der Bereich zum Klicken auf die einzelnen Mitglieder der Liste scheint sich über die gesamte Seite zu erstrecken, obwohl jedes Mitglied nur einen Teil der Seite füllt Bereiche überschneiden sich.Listview Element onItemClickListeners Überlappung
In diesem Beispiel stellt das Rot dar, wo der Klickbereich für das erste Listenmitglied sein sollte, und das Purpur stellt dar, wo es tatsächlich ist. Das Gleiche passiert mit allen anderen Mitgliedern, der höchste scheint den Vorrang zu haben.
Die Liste Mitglieder erstellt werden aus
panel_stream.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:elevation="4dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/panel_header_shape"
android:elevation="4dp"
android:id="@+id/header"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Update Title Here"
android:id="@+id/panelTitle"
android:layout_gravity="center_vertical"
android:elevation="4dp"
android:textColor="#eeeeee"
android:layout_alignParentTop="false"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:typeface="sans"
android:textSize="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Unattributed"
android:id="@+id/panelAuthor"
android:textColor="#dddddd"
android:textStyle="italic"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/header"
android:background="#ffffff"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:id="@+id/relativeLayout2"
android:layout_alignParentBottom="false">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#111111"
android:background="@drawable/panel_shape"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:id="@+id/panelContent"
android:layout_margin="5dp"
android:text="Content" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="@drawable/panel_footer_shape"
android:elevation="4dp"
android:layout_below="@+id/relativeLayout2"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:layout_alignParentBottom="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="0"
android:id="@+id/commentCount"
android:textColor="#000000"
android:textStyle="italic"
android:maxLines="1"
android:layout_toLeftOf="@+id/imageButton"
android:layout_toStartOf="@+id/imageButton"
android:layout_centerVertical="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton"
android:background="@mipmap/ic_comment_black_24dp"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_alignParentRight="true"
android:contentDescription="comment" />-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="2016-04-20 04:20:00"
android:id="@+id/dateStamp"
android:textColor="@color/colorAccent"
android:textStyle="italic"
android:maxLines="1"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_margin="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="@+id/panelID"
android:textColor="#00FFFFFF"
android:textStyle="italic"
android:maxLines="1" />
</RelativeLayout>
und sind in der Listview innerhalb> activity_board_stream_view.xml gelegt:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context="com.company.panels.BoardView"
android:background="@color/background"
android:id="@+id/mainLayout"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="4dp"
android:background="@color/colorPanel"
android:id="@+id/relativeLayout"
android:layout_alignParentBottom="false"
android:layout_marginTop="1dp"
android:layout_below="@+id/titleFrame" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sorting By"
android:id="@+id/textView"
android:textSize="18dp"
android:textColor="#222222"
android:gravity="center_vertical"
android:layout_margin="10dp"
android:layout_centerVertical="true" />
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/sortBy"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:spinnerMode="dropdown" />
</RelativeLayout>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/panelHost"
android:footerDividersEnabled="true"
android:background="@color/background"
android:layout_below="@+id/relativeLayout"
android:descendantFocusability="blocksDescendants"
android:elevation="4dp"
android:divider="#00FFFFFF" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="End of Content"
android:id="@+id/textView8"
android:layout_gravity="center"
android:layout_margin="10dp" />
Hier ist die onItemClickListener
BoardView.java:
package com.company.panels;
//Imports and irrelevant methods excluded
public class BoardView extends AppCompatActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mydb = new DBManager(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.board_stream_menu, menu);
setContentView(R.layout.activity_board_stream_view);
ListView listView = (ListView)findViewById(R.id.panelHost);
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
TextView dateStamp = (TextView)findViewById(R.id.panelID) ;
toViewPanel(dateStamp.getText().toString());
}});
return true;
}}
Post-Screenshot zu. –
Ich habe gerade einen hinzugefügt, um Klarheit zu schaffen. – Skyler
Bitte posten Sie Ihre 'OnItemClickListener' und die' getView() 'Methode Ihres' Adapters', wenn Sie einen eigenen verwenden. –