Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How can I compare the string in the array and perform an action to the list item if the string matches? @Override protected void onCreate(Bundle

How can I compare the string in the array and perform an action to the list item if the string matches?

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_list);

listView = findViewById(R.id.listView);

final ArrayList array = new ArrayList<>();

array.add("MainActivity"); array.add("FirstActivity"); array.add("SecondActivity");

ArrayAdapter arrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, array);

listView.setAdapter(arrayAdapter);

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { if(array.toString().equals("MainActivity")) { Intent mainAct = new Intent(ListActivity.this, MainActivity.class); startActivity(mainAct); }else if(array.toString().equalsIgnoreCase("FirstActivity")) { Intent firstAct = new Intent(ListActivity.this, MainActivity.class); startActivity(firstAct); }else if (array.toString().equalsIgnoreCase("SecondActivity")) { Intent secondAct = new Intent(ListActivity.this, MainActivity.class); startActivity(secondAct); } } });

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Technologies And Applications

Authors: Zongmin Ma

1st Edition

1599041219, 978-1599041216

More Books

Students also viewed these Databases questions

Question

What is cost plus pricing ?

Answered: 1 week ago

Question

1. What are the types of wastes that reach water bodies ?

Answered: 1 week ago

Question

Which type of soil has more ability to absorb water?

Answered: 1 week ago

Question

What are Measures in OLAP Cubes?

Answered: 1 week ago

Question

How do OLAP Databases provide for Drilling Down into data?

Answered: 1 week ago

Question

How are OLAP Cubes different from Production Relational Databases?

Answered: 1 week ago