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

  • Home
  • SEARCH
  • 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 6353253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:22:47+00:00 2026-05-24T22:22:47+00:00

Initially I am having a simple ListView Activity that consists of few formulae and

  • 0

Initially I am having a simple ListView Activity that consists of few formulae and also a Button at the top.Whenever I click that Button it takes me to another Activity,where in I am dragging and dropping the contents of the ListView.This Activity also consists a Button and whenever I click this Button the order of the contents which I have changed in my drag and drop Activity has to be saved in my initial Activity.How do I save the contents of ListView which I have changed in my drag and drop to my initial Activity?

Code:My Initial Activity and my next Activity is drag and drop.

   public class FormulaActivity extends Activity implements OnClickListener {

private ListView listview;
private ArrayList<ListContents> mListItem;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main1);
    ImageButton btn=(ImageButton)findViewById(R.id.imageButton00);
    btn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent i=new Intent(FormulaActivity.this,DragNDropListActivity.class);
            startActivity(i);


        }
    });
    listview = (ListView) findViewById(R.id.list_view);
    mListItem = ListContents.getItems();
    listview.setAdapter(new ListAdapter(FormulaActivity.this, R.id.list_view,
            mListItem));

}

@Override
public void onClick(View v) {

}

// ***ListAdapter***
private class ListAdapter extends ArrayAdapter<ListContents> { 
    private ArrayList<ListContents> mList; 
    public ListAdapter(Context context, int textViewResourceId,
            ArrayList<ListContents> list) { 
        super(context, textViewResourceId, list);
        this.mList = list;

    }

    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        try {
            if (view == null) {
                LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                view = vi.inflate(R.layout.list, null); 
            }
            final ListContents listItem = mList.get(position); 
            if (listItem != null) {
                // setting list_item views
                ((TextView) view.findViewById(R.id.tv_name))
                        .setText(listItem.getName());
                view.setOnClickListener(new OnClickListener() {


        public void onClick(View arg0) { // --clickOnListItem
                        Intent myIntent = new Intent(FormulaActivity.this,
                                Activity2.class);
                        myIntent.putExtra("NAME", listItem.getName());
                        startActivity(myIntent);
                        //finish();
                    }
                });
            }
        } catch (Exception e) {
            Log.i(FormulaActivity.ListAdapter.class.toString(), e.getMessage());
        }
        return view;
    }
}

}


public class DragNDropListActivity extends ListActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.dragndroplistview);
    Button mbtn=(Button)findViewById(R.id.button12);
    mbtn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
        Intent i=new Intent(DragNDropListActivity.this,FormulaActivity.class);
        startActivity(i);
        finish();
        }
    });
    ArrayList<String> content = new ArrayList<String>(mListContent.length);
    for (int i=0; i < mListContent.length; i++) {
        content.add(mListContent[i]);
    }

    setListAdapter(new DragNDropAdapter(this, new int[]{R.layout.dragitem}, new int[]{R.id.TextView01}, content));//new DragNDropAdapter(this,content)
    ListView listView = getListView();

    if (listView instanceof DragNDropListView) {
        ((DragNDropListView) listView).setDropListener(mDropListener);
        ((DragNDropListView) listView).setRemoveListener(mRemoveListener);
        ((DragNDropListView) listView).setDragListener(mDragListener);
    }
}

private DropListener mDropListener = 
    new DropListener() {
    public void onDrop(int from, int to) {
        ListAdapter adapter = getListAdapter();
        if (adapter instanceof DragNDropAdapter) {
            ((DragNDropAdapter)adapter).onDrop(from, to);
            getListView().invalidateViews();
        }
    }
};

private RemoveListener mRemoveListener =
    new RemoveListener() {
    public void onRemove(int which) {
        ListAdapter adapter = getListAdapter();
        if (adapter instanceof DragNDropAdapter) {
            ((DragNDropAdapter)adapter).onRemove(which);
            getListView().invalidateViews();
        }
    }
};

private DragListener mDragListener =
    new DragListener() {

    int backgroundColor = 0xe0103000;

        public void onDrag(int x, int y, ListView listView) {
            // TODO Auto-generated method stub
        }

        public void onStartDrag(View itemView) {
            itemView.setVisibility(View.INVISIBLE);
            itemView.setBackgroundColor(backgroundColor);
            ImageView iv = (ImageView)itemView.findViewById(R.id.ImageView01);
            if (iv != null) iv.setVisibility(View.VISIBLE);
        }

        public void onStopDrag(View itemView) {
            itemView.setVisibility(View.VISIBLE);
            itemView.setBackgroundColor(backgroundColor);
            ImageView iv = (ImageView)itemView.findViewById(R.id.ImageView01);
            if (iv != null) iv.setVisibility(View.VISIBLE);
        }

};

private static String[] mListContent={"BMI", "Infuusberekening: druppels per minuut", "Infuusberekening: resterende tijd","Injecteren: IE-aanduiding", "Injecteren: mg/ml-aanduiding", "Injecteren: %-aanduiding", 
                                    "Lichaamsoppervlakte", "Medicatieberekening voor gewicht",
                                    "Oplossen: Hoeveelheid percentage",
                                    "Oplossen: Hoeveelheid promillage",
                                    "Oplossen: Percentage in oplossing",
                                    "Oplossen: Promillage in oplossing",
                                    "PCA-pomp",
                                    "Procenten: delen",
                                    "Procenten: percentage",
                                    "Promillage: delen",
                                    "Promillage: percentage",
                                    "Spuitenpomp",
                                    "Verdunnen",
                                    "Voedingspomp: ml per uur",
                                    "Voedingspomp: resterende tijd",
                                    "Zuurstofberekening"};

}

  • 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-05-24T22:22:48+00:00Added an answer on May 24, 2026 at 10:22 pm

    Here is your solution :

    Declare new String array as

    public static String[] mNewPositions; 
    

    Add some codes in your mDropListener

        private DropListener mDropListener = 
            new DropListener() {
        public void onDrop(int from, int to) {
            ListAdapter adapter = getListAdapter();
            if (adapter instanceof DragNDropAdapter) {
                ((DragNDropAdapter)adapter).onDrop(from, to);
                getListView().invalidateViews();
    
                mNewPositions = new String[adapter.getCount()]; //Initialize your new items storage
    
                    for(int i=0; i < adapter.getCount(); i++) {
                        //Implement here your logic for save positions
                        mNewPositions[i] = adapter.getItem(i).toString();
                    }               
            }
        }
    };
    

    Now you have mNewPositions with new positioned data. Just access it and use when you want to use that.

    Hope it will clear.

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

Sidebar

Related Questions

I am having an error where my JQuery works initially upon radio click, but
I am having trouble doing something that is probably pretty simple! I have a
Initially I deployed packages on SQL server but since my machine is not having
I'm having a table and i have a row which is initially set to
I am having problem using mvc:resources in spring 3.1 configuration. Initially i was working
I'm having some problems with my program in VS .NET 2003. I initially wrote
I'm having a really irritating problem doing something that I'm sure I've done before.
I'm having some trouble successfully marshalling using the Marshaller.JAXB_FRAGMENT property. Here's a simple version
PROBLEM SOLVED: I was overlooking a very simple issue, and that is that this
I am having a problem that has had me stuck for a day and

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.