그래서 내가 뭘 하려는지 ListView 단추 OnLongClickListener 설정하려면 것입니다. 나는 그것에 OnClickListener를 넣을 수 있었고, 또한 전체 ListView에 OnLongItemClick을 넣으려고했지만 문제는 Item의 특정 Button을 누르면 OnLongItemClick이 호출되지 않는다는 것입니다.어떻게 ListView에서 OnLongClickListener를 Button으로 설정할 수 있습니까?
android : onClick = "myOnClickListener"를 사용하여 ListView-Rows의 XML 파일에있는 Button에 OnClickListener를 넣을 수는 있지만 OnLongClickListener에서는 작동하지 않습니다.
또한 OnLongClickListener를 일반 OnClickListener의 단추로 설정하려고했지만 정상적인 클릭만으로 정상적으로 작동하기 때문에 실제로 원하는 것은 아닙니다.
단추에 프로그래밍 방식으로 OnLongClickListener를 설정하는 방법이 있습니까? 그것들은 각각의 줄에서 독특해야합니다. Btw ListActivity를 확장하지 않습니다. 여기
이 버튼의 OnClickListener를 수 있습니다 :<?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:weightSum="40" >
<EditText
android:id="@+id/etAnzahl"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:layout_weight="5"
android:text="0" />
<!-- This is the Button i want to set a OnLongClickListener to. -->
<Button
android:id="@+id/bItemPlus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="25"
android:onClick="handlerForPlus"
android:text="Item" />
<Button
android:id="@+id/bItemMinus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="5"
android:onClick="handlerForMinus"
android:text="-" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:weightSum="10"
android:layout_weight="5"
android:orientation="vertical" >
<TextView
android:id="@+id/tvPriceItemSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="5"
android:text="PreisS" />
<TextView
android:id="@+id/tvPriceItemLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="5"
android:text="PreisL" />
</LinearLayout>
</LinearLayout>
그래서 누군가가 내 문제를 해결할 수 있는지 알 수 있습니까 : 여기
//I attached this in my XML-File to the Button
public void handlerForPlus(View v)
{
//The LinearLayout where all my Items are in
LinearLayout myItemLayout = (LinearLayout)v.getParent();
//A random EditText in my Layout
editTextCountItem = (EditText) myItemLayout.getChildAt(0);
//The Button i want to add the OnLongClickListener to
buttonItemPlus = (Button)myItemLayout.getChildAt(1);
//Here i set the OnLongClickListener to the button, but I want to do this before it gets clicked normally.
buttonItemPlus.setOnLongClickListener(this);
editTextCountItem.setText((Integer.toString(Integer.parseInt(editTextCountItem.getText().toString()) + 1)));
myItemLayout.refreshDrawableState();
}
하면 ListView에-항목의 LinearLayout을 내 XML 파일입니다 ?
최고 감사합니다.
buttonItemPlus.setOnLongClickListener (this)를 사용하면 잘 작동합니다. 버튼에,하지만 문제는 내가 한 번 정상적으로 버튼을 클릭 한 후이 OnClick 메서드를 의미합니다 내 OnClick - 메서드에서 사용하는 것입니다. 정상 onClick - 메서드 전에 setOnLongClickListener 사용할 수있는 위치를 알아야합니다. 또한 setOnItemLongClickListener 메서드는 Button에서 호출 할 수 없습니다. – user1950262