【发布时间】:2015-07-28 03:18:56
【问题描述】:
我有一个列表视图,其中包含两个按钮、一个文本视图和...
我想为一个按钮设置 onclicklistener 和一个 textview 来执行我在 onitemclicklistener 中为此列表视图设置的任何内容。但我不知道该怎么做。
这些是我的 lists.xml 代码
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="2dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="160dp"
android:layout_gravity="center_horizontal"
android:padding="15dp"
android:background="@android:drawable/dialog_holo_light_frame"
android:focusable="false"
android:focusableInTouchMode="false">
<FrameLayout
android:layout_width="132dp"
android:layout_height="120dp"
android:focusable="false"
android:focusableInTouchMode="false"
android:background="@drawable/company1"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:clickable="true"
android:id="@+id/frameLayout">
</FrameLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="@+id/id"
android:visibility="gone"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="35dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/company_name"
android:id="@+id/header_factory_list"
android:gravity="right"
android:focusable="false"
android:focusableInTouchMode="false"
android:textColor="#21313f"
android:textSize="15dp"
android:singleLine="true"/>
<RatingBar
style="@android:style/Widget.DeviceDefault.Light.RatingBar.Small"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ratingBar2"
android:animationResolution="3"
android:rating="2.5"
android:stepSize=".05"
android:layout_marginLeft="20dp"/>
<Button
android:layout_width="fill_parent"
android:layout_height="25dp"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="@string/add_fav_list"
android:id="@+id/button_add_fav_list"
android:background="#cf000f"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:textColor="#ffffff"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:padding="2dp"
android:textSize="10dp"/>
<Button
android:layout_width="fill_parent"
android:layout_height="25dp"
android:focusable="false"
android:text="@string/show_details"
android:id="@+id/button_detsils"
android:background="#21313f"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textColor="#ffffff"
android:layout_marginBottom="5dp"
android:padding="2dp"
android:textSize="10dp"/>
</LinearLayout>
</LinearLayout>
这些也是我来自 mainactivity 的 onitemclicklistener 代码:
Inside_Factory_ListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Inside_Factory_ListView.setVisibility(View.GONE);
TextView f= (TextView) view.findViewById(R.id.id);
Log.i("GETVIEW",view.getId()+"\n"+f.getText().toString());
setInfoInFactory(Integer.parseInt(f.getText().toString()));
Inside_Factory_Layout.setVisibility(View.VISIBLE);
final TranslateAnimation animation1 = new TranslateAnimation(0.0f, 0.0f,
3000.0f, 0.0f); // new TranslateAnimation(xFrom,xTo, yFrom,yTo)
animation1.setDuration(1500); // animation duration
animation1.setRepeatCount(0); // animation repeat count
animation1.setRepeatMode(0); // repeat animation (left to right, right to left )
//animation.setFillAfter(true);
Handler mHandler = new Handler();
Frist_Tab.setVisibility(View.VISIBLE);
Frist_Tab.startAnimation(animation1);
mHandler.postDelayed(new Runnable() {
public void run() {
Second_Tab.setVisibility(View.VISIBLE);
Second_Tab.startAnimation(animation1);
}
}, 1000);
mHandler.postDelayed(new Runnable() {
public void run() {
Third_Tab.setVisibility(View.VISIBLE);
Third_Tab.startAnimation(animation1);
}
}, 1000);
// Log.i("CLICK","CLICKED="+position);
if(L[1]){
L[2]=true;
}
}
});
我想要,当我点击按钮(进入列表视图)时,就像我点击列表视图的那个项目一样。
谁能帮帮我?
【问题讨论】:
-
@DanielNugent 我知道,但我想当我点击按钮时,按钮的 clicklistener 调用列表视图的“onitemclicklistener”。
-
你需要取出 OnItemClickListener。查看此答案以获取有关如何保留可能需要的功能的更多信息:stackoverflow.com/questions/1709166/…
-
@omidzamani 你可以使用一个接口来处理点击事件
-
@Kaushik 怎么样?能给我简单的代码吗?
-
@omidzamani 虽然这些点击事件在
ImageView上,但您可以在Buttons和TextView上设置它
标签: java android listview onclicklistener onitemclicklistener