一个解决方案是在对话框中声明文本视图。
我在对话框中有一个文本视图,我希望在单击该文本视图时执行某些操作
当我点击文本视图做某事时,我想要它。
我在布局中添加了可点击和点击
这是我的代码
public class Activitytwo extends ActionBarActivity {
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
//WORKING CODES
//WORKING CODES
//WORKING CODES
//WORKING CODES
}
// This one to show the dialog
//This one works fine!
public void share(View view){
sharedialog = new Dialog(Activitytwo.this);
sharedialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
sharedialog.setContentView(R.layout.postdialog);
sharedialog.setCanceledOnTouchOutside(true);
sharedialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
sharedialog.show();
}
public void facebookp(View view){
//This one for the TextView (onClick)
//This one doesn't work..
}
}
这是我的布局(postdialog.xml)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/postdialogl"
android:layout_width="match_parent"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_height="150dp"
android:background="@drawable/postdialog" >
<TextView
android:id="@+id/postdtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="20dp"
android:textSize="18sp"
android:textStyle="bold"
android:text="@string/post"
android:textColor="#a7b8d6"/>
<ImageView
android:id="@+id/poststrokea"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="#202e4c"
android:layout_below="@+id/postdtitle"
android:layout_marginTop="5dp"/>
<ImageView
android:id="@+id/poststrokeb"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="#803e5482"
android:layout_below="@+id/poststrokea"/>
<TextView
android:id="@+id/facebookpost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="60dp"
android:layout_marginLeft="30dp"
android:drawablePadding="5dp"
android:text="@string/facebook"
android:textColor="#a7b8d6"
android:textSize="12sp"
android:drawableTop="@drawable/facebook"
android:clickable="true"
android:onClick="facebookp"/>
</RelativeLayout>
public void share(View view){
//your code.
sharedialog = new Dialog(Activitytwo.this);
sharedialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
sharedialog.setContentView(R.layout.postdialog);
sharedialog.setCanceledOnTouchOutside(true);
sharedialog.getWindow().setBackgroundDrawable(newColorDrawable(android.graphics.Color.TRANSPARENT));
final TextView tviPost = (TextView) sharedialog.findViewById(R.id.sharedialog);
tviPost.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
//Do something
}
});
sharedialog.show();
}
并从布局中删除下一行。
android:clickable="true"
android:onClick="facebookp"