0

I am using Xamarin and I have a ListView activity with some Custom Views. I also have a map activity. The map activity starts as the start up project. After the map activity has started up, I wish to display a ListView (that is currently in an activity).

My question is this: Do I need to start a new activity, with an intent, to display this ListView? Can I display a ListView from my map activity?

Thanks in advance

Garry
  • 1,251
  • 9
  • 25
  • 45

2 Answers2

0

You can make an AlertDialog which can be launched from current Activity by creating a Custom Layout for AlertDialog.

MainActivity.java

package com.example.alertlist;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.view.LayoutInflater;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends Activity {

AlertDialog al;
ListView lv;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    AlertDialog.Builder b = new AlertDialog.Builder(this);
    LayoutInflater i = getLayoutInflater();
    b.setView(i.inflate(R.layout.alert_list, null));
    al = b.create();
    al.show();
    lv = (ListView) al.findViewById(R.id.listView1);
    String[] myStringArray = {"this", "is", "it"};
    ArrayAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, myStringArray);
    lv.setAdapter(adapter);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}

alert_list.xml

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

<ListView
    android:id="@+id/listView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
</ListView>

</LinearLayout>
Osama Mohammed Shaikh
  • 1,219
  • 1
  • 16
  • 40
0

You can remove all views from content view of current Activity and create your ListView in code then add it to your content view.Or you can use switchView to show it.Also you can create a layout that has your map and list,at first set your list invisible and then set your map invisible and change list visible.

1-

ViewGroup vg = (ViewGroup)(mapView.getParent());
vg.removeView(mapView);

//then create your listview and add it:
...
vg.addView(myListView);

2-If you want change visibility,see Android : difference between invisible and gone?

Finally you can search in about switching views in android,It will be useful.

Community
  • 1
  • 1
hasanghaforian
  • 13,858
  • 11
  • 76
  • 167