Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9234839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:53:02+00:00 2026-06-18T06:53:02+00:00

I have a Viewpager in a Fragment activity and it has a botton frame

  • 0

I have a Viewpager in a Fragment activity and it has a botton frame with the edit text and send button.
In the fragment layout i have a Listview and am attaching an adapter to it in fragment. Now am implementing the send button from the Parent inside the fragment, on click am trying to add the text in the edit text(again from the parent) to the List(in the fragment) via adapter. But issue here is when i enter some text and click send its adding the text not to the current view in the pager but to next, and when i go to the last item some times it adds to the same view(which is expected). Some times its random not in the order of next item.
Fragment Activity layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/detailLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="true"
    android:orientation="vertical" >

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/form" >
    </android.support.v4.view.ViewPager>

    <RelativeLayout
        android:id="@+id/form"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal"
        android:padding="2dp" >

        <EditText
            android:id="@+id/editText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_toLeftOf="@+id/btnSend"
            android:drawableRight="@drawable/edit_keyboard"
            android:inputType="textMultiLine"
            android:maxLines="3" />

        <ImageButton
            android:id="@+id/btnSend"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:src="@drawable/send" />
    </RelativeLayout>

</RelativeLayout>

The fragment Layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <ListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent"
        android:cacheColorHint="@android:color/transparent"
        android:divider="@android:color/transparent"
        android:listSelector="@android:color/transparent"
        android:scrollbars="none" />

</RelativeLayout>

Here’s how am implementing the send ImageButton:

ImageButton sendBtn = (ImageButton) getActivity().findViewById(R.id.btnSend);

sendBtn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                String msg = msgBox.getText().toString();
                if (msg.length() > 0) {
                    long date = new Date().getTime();
                    // TODO Auto-generated method stub
                    commentAdapter.add(new OneComment(false, msg, "Me",
                    String.valueOf(date), "0"));

                    msgBox.setText("");
                } else
                    Toast.makeText(getActivity(), "type in some text..", Toast.LENGTH_SHORT).show();
            }
        });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T06:53:03+00:00Added an answer on June 18, 2026 at 6:53 am

    You can access to the current fragment (the one with list) doing something like this:

    Fragment currentFragment = (Fragment) viewPager.getAdapter().instantiateItem(viewPager, viewPager.getCurrentItem()); //gets current fragment
    //now you have to cast it to your fragment with list, let's say it's name is SukarnoListFragment
    
    ((SukarnoListFragment)currentFragment).messageList.add(...); // you have now access to public fields and methods that are inside your fragment
    

    And I think that if you have your button in Activity then you should implement onClick of this button in your Activity, not in your fragment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this structure: Activity A has a ViewPager. The pages of a ViewPager
I have a FragmentActivity this activity has a Fragment this Fragment consist from widgets
I have a viewpager with 2 pages, on each fragment i put a button
I have a ViewPager with Fragment s. When a button is clicked in the
So I have an Activity which has a FragmentPagerAdapter and inside each fragment I
I have a ViewPager with multiple fragments. In one Fragment I play audio. When
I have a listview which has a list of places - i have the
I have an activity 3ChartPerTabActivity where i have 3 tabs fragment with Viepager.Each fragment
I have a ViewPager with 3 Fragments in there. Each Fragment uses a AsyncTaskLoader
I have Fragment activity with pager: List<Fragment> fragments = new Vector<Fragment>(); fragments.add(Fragment.instantiate(this, PastEventListFragment.class.getName(),bundle)); fragments.add(Fragment.instantiate(this,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.