0
在我的一個活動Surah.java
中,我使用了custom_dialogue和custom_dialog.xml
來提示用戶。該對話框包含兩個按鈕。我只想處理這兩個按鈕的click events
。我已經寫過custom_dialog.java
的處理程序,但這沒有什麼區別。ButtonClikListner事件未在Custom_dialogue中觸發| Android
custom_dialog.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<Button android:id="@+id/ok"
android:layout_width="90dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:text="OK" />
<Button android:id="@+id/cancel"
android:layout_width="90dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:text="Cancel" />
</LinearLayout>
</LinearLayout>
custom_dialog.java
package com.quran.peacequran;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class custom_dialog extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.custom_dialog);
Button button= (Button) findViewById(R.id.cancel);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "No stores", 5000).show();
}
});
}
}
Surah.java
package com.quran.peacequran;
import java.util.ArrayList;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class Surah extends Fragment {
....
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
MyAdapter adapter = new MyAdapter(getActivity(), generateData());
// 2. Get ListView from activity_main.xml
ListView listView = (ListView) getView().findViewById(R.id.listView1);
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> arg0, View v,int index, long arg3) {
Toast.makeText(getActivity(),"thul thuk!",Toast.LENGTH_SHORT).show();
Dialog dialog = new Dialog(getActivity());
dialog.setContentView(R.layout.custom_dialog);
dialog.setTitle("BookMark Surah?");
dialog.show();
return false;
}
});
}
...
}
其顯示錯誤! @ user3274687 –
什麼錯誤?哪一行請具體說明? – Aritra
「這樣的方法不存在」 –