How to go to another activity using intent in custom adapter

This is my Adapter and EditMeal Activity.My main activity have only listView. Inside this adapter have many different edittext component. And i want to pass my info which is display on my listview in main activity to editMealActivity when listview is clicked.

Answers

  • Grace1234Grace1234 Member ✭✭
    edited November 30

    This is what in my custom adapter, Full coding in that document

  • Grace1234Grace1234 Member ✭✭

    This is my editMealActivity

  • JarvanJarvan Member, Xamarin Team Xamurai

    Save the data in a Bundle and add a set of extended data to the intent using Intent.putExtras method. Retrieves the extended data from the intent, then set it for EditText.

    MainActivity class

    public class MainActivity extends AppCompatActivity {
        @Override
        protected void onCreate(final Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            list = new ArrayList<String>();
            list.add("Vegetables");
            ...
    
            Adapter_ adapter = new Adapter_(this,R.layout.layout1,list);
    
            ListView listview = (ListView)findViewById(R.id.listview);
            listview.setAdapter(adapter);
    
            listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    
                    Intent intent = new Intent(MainActivity.this,NavgationActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putString("pass_value", list.get(position));
    
                    intent.putExtras(bundle);
                    startActivity(intent);
                }
            });
        }
    }
    

    NavgationActivity class

    public class NavgationActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.layout2);
    
            EditText editText = (EditText)findViewById(R.id.edit);
    
            Bundle bundle = getIntent().getExtras();
    
            if(bundle!=null)
            {
                String pass_value = bundle.getString("pass_value");
                editText.setText(pass_value);
            }
        }
    }
    

    Besides, the forums is about Xamarin. For native Android problem with jave, you can post such issues on stackoverflow where experts can better assist.

Sign In or Register to comment.