2014-07-23 22 views
-1

我有一个项目延长片段在片段的EditText到列表视图,数据传输

现在,我的项目有三个标签。 它是组成片段。

写!!!!在第一个标签中编辑文本→推!!!!添加按钮→查看!!!!在第二个标签列表视图

请..帮助我!

final Button btn1 = (Button) view.findViewById(R.id.ButtonAdd); 
btn1.setOnClickListener(new View.OnClickListener() { 
@Override 
public void onClick(View v) {    
    String str = mEditMAC.getText().toString();  
    }); 

public View getView(int position, View convertView, ViewGroup parent) { return parent;

回答

0

片段之间的基本通信是 片段 - >活动 - >另一片段

这里是从片段至活动回调的代码示例。 您可以在http://developer.android.com/training/basics/fragments/communicating.html

FirstFragment

public class FirstFragment extends Fragment { 
    public interface OnBtnClickListener { 
     public void buttonClicked(String mac); 
    } 
    OnBtnClickListener mCallback; 

    @Override 
    public void onAttach(Activity activity) { 
     super.onAttach(activity); 

     // This makes sure that the container activity has implemented 
     // the callback interface. If not, it throws an exception 
     try { 
      mCallback = (OnBtnClickListener) activity; 
     } catch (ClassCastException e) { 
      throw new ClassCastException(activity.toString() 
       + " must implement OnBtnClickListener"); 
     } 
    } 

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

     final Button btn1 = (Button) view.findViewById(R.id.ButtonAdd); 
     btn1.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) {    
       String str = mEditMAC.getText().toString(); 
       mCallback.buttonClicked(str); 
      }  
     }); 
    } 
} 

活动

public class YourActivity extends Activity implements FirstFragment.OnBtnClickListener { 
    @Override 
    public void buttonClicked(String mac) { 
     // find second fragment and call the proper function 
     SecondFragment fragment = (SecondFragment)getSupportFragmentManager().findFragmentByTag(SecondFragment.TAG); 
     if (fragment != null) { 
      fragment.buttonClicked(mac); // update second fragment's listview 
     } 
    } 
} 
+0

我试试这个代码中找到更详细的代码。但它是失败的...我想发电子邮件给你我的项目..我可以问你的电子邮件吗? –

+0

显示错误日志。 –

+0

我想显示错误日志,但我的项目有很多类。我在互联网上下载了这个项目文件。所以我很难理解这个项目.. –