Android RelativeLayout und OnClickListener
Fand ich viele viele threads und Antworten auf, wie man ein Relative layout reagieren auf Ereignis klicken. Ich habe implementiert, die mein layout nach Ihnen. Aber noch OnClickListener ist nicht genannt. Ich habe auch Selektor für es und es funktioniert gut.
my_list_item xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/air.com.jingit.mobile"
android:layout_width="match_parent" android:layout_height="@dimen/actionBarHeight"
android:clickable="true"
android:background="@drawable/my_list_selector">
<com.loopj.android.image.SmartImageView
android:layout_width="@dimen/actionBarHeight"
android:layout_height="@dimen/actionBarHeight"
android:id="@+id/image"
android:scaleType="fitCenter"
android:layout_marginLeft="20dp"
android:clickable="false"
android:focusable="false"/>
<com.uma.mobile.view.CustomTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Loading..."
android:id="@+id/userName"
app:typeface="fonts/HelveticaNeue"
app:customStyle="Regular"
android:textSize="20sp"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/image"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:textColor="#000"
android:clickable="false"
android:focusable="false"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#aaa"
android:layout_alignBottom="@+id/image"></FrameLayout>
und das ist, wo ich aufblasen der Ansicht:
public MyListItem(final Context context, final Integer retailerId) {
super(context);
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater.inflate(R.layout.my_list_item, this);
image = (SmartImageView) view.findViewById(R.id.image);
userName = (CustomTextView) view.findViewById(R.id.userName);
setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.i("INSIDE LIST","CLICK");
}
});
}
Edit 1:
Diese Relative layout Hinzugefügt linearer Anordnung, die innerhalb einer scrollview, so dass es funktioniert wie in einer Liste anzeigen. Hat dies etwas damit zu tun hat???
list_view.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:background="#eee">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/scrollView" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/listContainer" />
</ScrollView>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:layout_centerHorizontal="true"
android:src="@drawable/up_indicator"
android:layout_alignBottom="@+id/scrollView" />
- verwenden
android:clickable="true"
stattandroid:clickable="false"
Layout Anklickbar - anzeigen verwenden.setOnClickListener
- Selbst das hat nicht funktioniert.
- Ich habe
android:clickable="true"
für das layout - Ich habe bearbeitet die Frage. Jede Idee zu diesem?
- Ich habe bearbeitet Sie meine Frage. Können Sie, um es so Aussehen.
Du musst angemeldet sein, um einen Kommentar abzugeben.
Einmal hatte ich einen
RelativeLayout
nicht feuernonClick
Veranstaltung und es war denn ich hatte eineButton
in der Mitte, und dieButton
's onClick-Ereignis wurde gefeuert, statt derRelativeLayout
ein. Gelöst Implementierung einer listener für beide von Ihnen:Hoffe, es hilft!
Hinzufügen
OnClickListener
in IhremRelativeLayout java Class