Click here to Skip to main content
13,248,562 members (75,911 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
I have created a tabbed activity with viewpager with two tabs and I want to send two text as title and description from tab one(contains the two edittexts) to tab two(contains the listview).
my fragment_one.java :
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
 
    Button btnPassData = (Button) view.findViewById(R.id.btnPassData);
    final EditText inData = (EditText) view.findViewById(R.id.inMessage);
    btnPassData.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            SM.sendData(inData.getText().toString().trim());
        }
    });
 
}

and fragment_two.java :

public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
 
    listView = (ListView) view.findViewById(R.id.list_view);
    adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, arrayList);
 
    listView.setAdapter(adapter);
}
 
protected void displayReceivedData(String message) {
    arrayList.add(message);
    adapter.notifyDataSetChanged();
 
}

and my custom_listview is :
<ImageView
    android:id="@+id/icon"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:padding="5dp" />
 
<LinearLayout android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">
 
    <TextView
        android:id="@+id/item"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Medium Text"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="5dp"
        android:padding="2dp"
        android:textColor="#33CC33" />
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:layout_marginLeft="10dp"/>
</LinearLayout>

main activity.java :
public class MainActivity extends AppCompatActivity implements FragmentOne.SendMessage{
 
    TabLayout tabLayout;
    ViewPager viewPager;
    ViewPagerAdapter viewPagerAdapter;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
 
        viewPager = (ViewPager) findViewById(R.id.viewPager);
        viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());
        viewPager.setAdapter(viewPagerAdapter);
        tabLayout = (TabLayout) findViewById(R.id.tabs);
        tabLayout.setupWithViewPager(viewPager);
    }
 
    @Override
    public void sendData(String message) {
        String tag = "android:switcher:" + R.id.viewPager + ":" + 1;
        FragmentTwo f = (FragmentTwo) getSupportFragmentManager().findFragmentByTag(tag);
        f.displayReceivedData(message);
    }
}


What I have tried:

I have asked before in stockoverflow but no one help me good>>?
Posted 8-Nov-17 20:55pm
Updated 5 days ago
v2
Comments
David Crow 9-Nov-17 10:19am
   
What is SM in fragment_one.java? What is sendData() in fragment_two.java? You show a portion of custom_listview.xml but don't show where/how its used. Where is displayReceivedData() called from? As this is not really a Q&A type post, this is really one of those situations where you should have used the actual Android forum instead. That aside...

Have you seen this?
Member 13366692 10-Nov-17 10:58am
   
I'm sorry I forgot
See the question I added some the edits......!!!!!
wseng 12-Nov-17 11:23am
   
You want to pass this two text when button clicked ?

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

yes...! please help me ?
this my email monzir.go@gmail.com if you want to contact >>>!
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web01 | 2.8.171114.1 | Last Updated 13 Nov 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100