<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                **主要實現功能:** 1、從Activity的TextView中獲取字符串設置到AlertDialog的TextView和EditText中 2、將AlertDialog的EditText中的值設置到Activity的TextView中 效果: ![](https://box.kancloud.cn/2016-03-01_56d5568e48191.jpg) ??![](https://box.kancloud.cn/2016-03-01_56d5568e62672.jpg) ??![](https://box.kancloud.cn/2016-03-01_56d5568e78363.jpg) 新手在自定義AlertDialog上的疑問筆者猜測主要有**兩個**: 1、自定義的layout如何放到AlertDialog中? 解答: 獲取到layout的view之后,直接調用AlertDialog.Builder的setView方法即可。 2、如何對自定義AlertDialog中的控件進行操作? 解答: 于fragment中的操作類似,首先要獲取該layout的view,然后通過該view獲取到其中控件進行操作。 MainActivity: ~~~ package com.example.myalertdialog; import android.app.Activity; import android.content.DialogInterface; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends Activity { TextView old_name; Button bt_change_name; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); old_name = (TextView) findViewById(R.id.tv_name); bt_change_name = (Button) findViewById(R.id.bt_name); bt_change_name.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //獲取自定義AlertDialog布局文件的view LinearLayout change_name = (LinearLayout) getLayoutInflater() .inflate(R.layout.my_dialog, null); TextView tv_name_dialog = (TextView) change_name.findViewById(R.id.tv_name_dialog); //由于EditText要在內部類中對其進行操作,所以要加上final final EditText et_name_dialog = (EditText) change_name.findViewById(R.id.et_name_dialog); //設置AlertDialog中TextView和EditText顯示Activity中TextView的內容 tv_name_dialog.setText(old_name.getText().toString()); et_name_dialog.setText(old_name.getText().toString()); new AlertDialog.Builder(MainActivity.this) .setTitle("修改用戶名") .setView(change_name) .setPositiveButton("確定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //將Activity中的textview顯示AlertDialog中EditText中的內容 //并且用Toast顯示一下 old_name.setText(et_name_dialog.getText().toString()); Toast.makeText(MainActivity.this, "設置成功!", Toast.LENGTH_SHORT).show(); } }) //由于“取消”的button我們沒有設置點擊效果,直接設為null就可以了 .setNegativeButton("取消", null) .create() .show(); } }); } } ~~~ activity_main.xml: ~~~ <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="10dp"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#000" android:text="原用戶名:" /> <TextView android:id="@+id/tv_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="大西瓜" /> </LinearLayout> <Button android:id="@+id/bt_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="修改用戶名" /> </LinearLayout> ~~~ my_dialog.xml: ~~~ <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="10dp"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#000" android:text="原用戶名:" /> <TextView android:id="@+id/tv_name_dialog" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Hello World!" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#000" android:text="新用戶名" /> <EditText android:id="@+id/et_name_dialog" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Hello World!" /> </LinearLayout> </LinearLayout> ~~~ 源碼地址:[http://download.csdn.net/detail/double2hao/9411213](http://download.csdn.net/detail/double2hao/9411213)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看