android设置弹出视图上的文本

时间:2012-08-01 10:13:29

标签: android textview android-fragments

我有一个应用程序片段正常工作,

我有一个带按钮的视图,当点击按钮时,会显示一个弹出视图,

但我需要在弹出视图中为每个按下的按钮设置不同的文本。

我是android和java的新手,刚刚意识到我不明白如何将数据发送到弹出视图,在弹出视图的xml上设置文本,

public class Tab2HeadH1 extends Fragment   implements OnClickListener{

    //testeo popero


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {



        View view = inflater.inflate(R.layout.tab_2_head_buttons, container,false);



        //Buttons

        final Button buttonNose = (Button) view.findViewById(R.id.button_pop_nose);

        buttonNose.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(final View v) {
              //aqui tus tareas,,

                LayoutInflater layoutInflater = (LayoutInflater)getActivity().getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

               View popupView = layoutInflater.inflate(R.layout.popup, null);  
                        final PopupWindow popupWindow = new PopupWindow(
                          popupView, 
                          LayoutParams.WRAP_CONTENT,  
                                LayoutParams.WRAP_CONTENT);

                        Button btnDismiss = (Button)popupView.findViewById(R.id.dismiss);
                        btnDismiss.setOnClickListener(new Button.OnClickListener(){

                @Override
                public void onClick(View v) {
                 // TODO Auto-generated method stub
                 popupWindow.dismiss();
                }});

                        popupWindow.showAsDropDown(buttonNose, 50, 30);




            }



        });





        Button buttonEye = (Button) view.findViewById(R.id.button_pop_eye);

        buttonEye.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(final View v) {
               // onLoginClicked(v);
                Toast.makeText(getActivity(), "ss9 eye",
                        Toast.LENGTH_SHORT).show();

            }
        });

return view;
    }



    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {

        super.onViewCreated(view, savedInstanceState);



        ((TabActivity)getActivity()).setHeader("TAPING APPLICATION");
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch (v.getId()) {



        }
    }


}

和xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" 
    android:background="@android:color/background_light">
 <LinearLayout 
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:orientation="vertical" 
     android:layout_margin="1dp"
     android:background="@android:color/darker_gray">
     >
     <LinearLayout 
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="vertical" 
      android:layout_margin="20dp">
      <TextView
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="It's a PopupWindow" />
      <ImageView
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:src="@drawable/ic_launcher" />
      <Button
          android:id="@+id/dismiss"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="Dismiss" />
      </LinearLayout>
 </LinearLayout>
</LinearLayout>

那么如何设置textView的文本,

非常感谢!

1 个答案:

答案 0 :(得分:2)

您需要在弹出布局中找到textView并设置弹出文本

TextView text = popupView.findViewById(R.id.popup_text);
text.setText(your text);