我有兩個dialog fragments
。將參數從第二個傳遞給第一個對話框片段
我在第一dialog fragment
一個TextView
當用戶點擊它,即可轉到用戶添加在EditText
意見第二dialog fragment
。當用戶輸入他的評論完成後,點擊done
按鈕返回到第一個dialog fragment
。到目前爲止這麼好,工作。
我的問題是如何傳遞和分配參數(user comment
)到第一個dialog fragment textView
?
首先DialogFragment
namespace MyApp
{
public class Report:DialogFragment
{
String comment;
public Report()
{
}
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
base.OnCreateView (inflater, container, savedInstanceState);
var view = inflater.Inflate(Resource.Layout.Report, container, false);
var textView = view.FindViewById<TextView> (Resource.Id.comment);
textView.Click += TextView_Click;
return view;
}
void TextView_Click (object sender, EventArgs e)
{
ShowDialog();
}
public void ShowDialog()
{
var transaction = FragmentManager.BeginTransaction();
var dialogFragment = new Comment();
dialogFragment.Show(transaction, "dialog_fragment");
}
}
}
二DialogFragment
namespace MyApp
{
public class Comment:DialogFragment
{
EditText comment;
public Comment()
{
}
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
base.OnCreateView (inflater, container, savedInstanceState);
var view = inflater.Inflate(Resource.Layout.Comment, container, false);
comment = view.FindViewById<EditText> (Resource.Id.myText);
Button doneBtn = view.FindViewById<Button> (Resource.Id.doneBtn);
doneBtn.Click += DoneBtn_Click;
return view;
}
void DoneBtn_Click (object sender, EventArgs e)
{
String str = comment.Text;
Console.WriteLine (str);
this.Dismiss();
}
}
}
這是什麼語言? – lustig
你做過任何研究或嘗試過任何東西嗎?那裏有很多信息。 –
這是C# - Xamarin.Android平臺 – hotspring