Я разрабатываю приложение для чата для Android.Проблемы с popupWindow
Я застрял, показывая контакты в popupWindow. То, что я притворяюсь, это показать их в правой части экрана, например google + показывает меню. Проблема в том, что я искал многие структуры, чтобы показать их, и, наконец, тот, который я видел, который не устарел, - popupWindow. Пожалуйста, если это не так, я буду благодарен за вашу помощь.
Когда я пытаюсь выполнить код, я получил эту ошибку (я пробовал много вещей, и на самом деле это то, что у меня есть): java.lang.NullPointerException: попытка вызвать виртуальный метод void android.widget.TextView .setText (java.lang.CharSequence)»на нулевой ссылки на объект в osmuogar.letter.interfaz.conversacion.Sala.showContacts (Sala.java:100)
кода Java ---
public void showContacts(MenuItem item){
LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
final ViewGroup popupView = (ViewGroup)layoutInflater.inflate(R.layout.lista_amigos, null);
PopupWindow popupWindow = new PopupWindow(popupView, RadioGroup.LayoutParams.WRAP_CONTENT,
RadioGroup.LayoutParams.WRAP_CONTENT);
final LinearLayout layout = (LinearLayout) popupView.findViewById(R.id.linearLayoutAmigos);
layout.inflate(popupView.getContext(),R.layout.contact,null);
TextView contactName = (TextView) layout.findViewById(R.id.contactname);
contactName.setText("contacto1");
popupView.addView(layout);
popupWindow.setFocusable(true);
popupWindow.update();
popupWindow.showAtLocation(findViewById(R.id.mainLayout), Gravity.RIGHT,0,0);
Мои макеты --- --lista_amigos
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/scrollViewAmigos">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linearLayoutAmigos">
</LinearLayout>
</ScrollView>
</LinearLayout>
--contact
<?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:layout_gravity="left"
android:background="#ffffff">
<TextView
android:id="@+id/contactname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imageView"
android:text="contact"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/black"
android:textSize="24sp" />
</RelativeLayout>
Спасибо за вашу помощь.
удалить андроид: layout_toRightOf = "@ + id/imageView" в вашем Textview – sasikumar
Это фрагмент или активность? – sasikumar
Это часть деятельности, но не сама деятельность. Он выполняется, когда кто-то нажимает кнопку. Цистерны для вашей помощи –