Many of you know, that there's is a class RealViewSwticher created by Marc Reichelt http://marcreichelt.blogspot.com/2010_09_01_archive.html
If someone used or uses this thing, please can you help me.
Here's my .xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<de.marcreichelt.android.RealViewSwitcher
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/real_view_switcher">
<GridView android:id="#+id/gridView1" android:layout_width="match_parent" android:layout_height="match_parent"></GridView>
<GridView android:id="#+id/gridView2" android:layout_width="match_parent" android:layout_height="match_parent"></GridView>
</de.marcreichelt.android.RealViewSwitcher>
</LinearLayout>
And here's my main class.
public class MyMain extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
RealViewSwitcher realViewSwitcher = (RealViewSwitcher)findViewById(R.id.real_view_switcher);
GridView gridview = (GridView) findViewById(R.id.gridView1);
GridView gridview2 = (GridView) findViewById(R.id.gridView2);
gridview.setAdapter(new ImageAdapter(this));
gridview2.setAdapter(new ImageAdapter(this));
realViewSwitcher.setOnScreenSwitchListener(onScreenSwitchListener);
}
private final RealViewSwitcher.OnScreenSwitchListener onScreenSwitchListener = new RealViewSwitcher.OnScreenSwitchListener() {
#Override
public void onScreenSwitched(int screen) {
// this method is executed if a screen has been activated, i.e. the screen is completely visible
// and the animation has stopped (might be useful for removing / adding new views)
Log.d("RealViewSwitcher", "switched to screen: " + screen);
}
};
}
I really don't understand what i am doing wrong, in the Example there's comment how to use it in xml:
// note that you can also define your own views directly in a resource XML, too by using:
// <de.marcreichelt.android.RealViewSwitcher
// android:layout_width="fill_parent"
// android:layout_height="fill_parent"
// android:id="#+id/real_view_switcher">
// <!-- your views here -->
// </de.marcreichelt.android.RealViewSwitcher>
The problem is: It is not working. I can see only my main GridView and i can't scroll to the second. If soemeone knews how where i made a mistake or if someone knews another way to do a real scrolling between views, please answer this.
why don't you use ScrollView? Try to use something like this:
<ScrollView android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="110px">
<LinearLayout
android:id="#+id/grds"
android:drawingCacheQuality="low"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<GridView android:id="#+id/gridView1" android:layout_width="match_parent" android:layout_height="match_parent"></GridView>
<GridView android:id="#+id/gridView2" android:layout_width="match_parent" android:layout_height="match_parent"></GridView>
</LinearLayout>
</ScrollView>
if it does't work, looak at this post
Switching between two GridViews in the same Activity
Related
obviously not a profound question, but I think theres probably an error in my approach.
So I've added the file listview.xml to my project in the layout folder.
it contains this:
<?xml version="1.0" encoding="utf-8"?>
<ListView android:id="#+id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android" />
I've also tried:
<?xml version="1.0" encoding="utf-8"?>
<ListView android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android" />
And i my main activity function generally looks like this:
public class ToDoManagerActivity extends ListActivity {
private static final int ADD_TODO_ITEM_REQUEST = 0;
private static final String FILE_NAME = "TodoManagerActivityData.txt";
private static final String TAG = "Lab-UserInterface";
// IDs for menu items
private static final int MENU_DELETE = Menu.FIRST;
private static final int MENU_DUMP = Menu.FIRST + 1;
ToDoListAdapter mAdapter;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create a new TodoListAdapter for this ListActivity's ListView
mAdapter = new ToDoListAdapter(getApplicationContext());
// Put divider between ToDoItems and FooterView
getListView().setFooterDividersEnabled(true);
// TODO - Inflate footerView for footer_view.xml file
TextView footerView = (TextView) getLayoutInflater().inflate(R.layout.footer_view, null);
// NOTE: You can remove this block once you've implemented the assignment
if (null == footerView) {
return;
}
// TODO - Add footerView to ListView
getListView().addFooterView(footerView);
setListAdapter(mAdapter);
setContentView(R.layout.footer_view);
This keeps breaking with the error:
...java.lang.RunTimeException: content must have a ListView whose id attribute is 'android.R.id.list'
I noticed that if I comment out the setContentView(R.layout.footer_view) bit the error disappears, which is quite confusing as well, because it seems like the error should trigger before there.
This is confusing the hell out of me because as far as I can tell this element exists. Its seems like maybe I'm missing a step to load the ListView? I'm banging my head against the wall here and this seems like something really basic, and being a n00b sucks...So any help is much appreciated!
Cheers!
EDIT:
footer_view.xml contents:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/footerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="#string/add_new_todo_item_string"
android:textSize="24sp" >
</TextView>
EDIT2:
Current onCreate after suggested edits:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create a new TodoListAdapter for this ListActivity's ListView
mAdapter = new ToDoListAdapter(getApplicationContext());
// Put divider between ToDoItems and FooterView
getListView().setFooterDividersEnabled(true);
setListAdapter(mAdapter);
TextView footerView = (TextView) getLayoutInflater().inflate(R.layout.footer_view, getListView(), false);
getListView().addFooterView(footerView);
}
For an Activity that is extending ListActivity, the ListView needs to exist within the xml file that you are using in the activity, in your case that's the footer_view file.
Taken from the Google Dev Site - "ListActivity has a default layout that consists of a single, full-screen list in the center of the screen. However, if you desire, you can customize the screen layout by setting your own view layout with setContentView() in onCreate(). To do this, your own view MUST contain a ListView object with the id "#android:id/list""
To incorporate your footer below your list, try this:
<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="#android:id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<TextView
android:id="#+id/footerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="#string/add_new_todo_item_string"
android:textSize="24sp" >
</TextView>
</LinearLayout>
Here, try this in your layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/black"
android:id="#android:id/list" />
</LinearLayout>
That is exactly what I have in my app.
Then in your onCreate(), just this:
setContentView(R.layout.activity_main);
Try it and let me know if it works. That code should work. From there, we can continue on to isolate the problem.
EDIT:
Man, now I see your problem. Not a big deal here. Let's look at your code (edited to be shorter). The onCreate() method has this:
super.onCreate(savedInstanceState);
mAdapter = new ToDoListAdapter(getApplicationContext());
getListView().setFooterDividersEnabled(true);
TextView footerView = (TextView) getLayoutInflater().inflate(R.layout.footer_view, null);
getListView().addFooterView(footerView);
setListAdapter(mAdapter);
setContentView(R.layout.footer_view);
Do you see R.layout.activity_main anywhere there? There's your issue! Your R.layout.footer_view only contains a textview, it doesn't contain the ListView, and your Activity keeps looking for the ListView that you promised it that you'd have by extending a ListActivity.
Try this - change your onCreate() method to this:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAdapter = new ToDoListAdapter(getApplicationContext());
setListAdapter(mAdapter);
}
Then your activity_main.xml layout file should look like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/black"
android:id="#android:id/list" />
</LinearLayout>
This should work. Let me know.
EDIT2:
Now add this to the end of your onCreate() method:
TextView footerView = (TextView) getLayoutInflater().inflate(R.layout.footer_view, null);
getListView().addFooterView(footerView);
Voila! Should work now.
ListView is not detected in Custom.Class when bridging from custom.xml file ..i have done some silly mistake please correct me..
public class Custom extends Activity {
/* (non-Javadoc)
* #see android.app.Activity#onCreate(android.os.Bundle)
*/
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.custom);
ListView lv=(ListView)findViewById(R.id.list); // list is not detected..showing error
}
}
XML custom
<?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/android:list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
Replace
<ListView
android:id="#id/android:list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
with
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
Whenever you want to give id to a View you have to use android:id="#+id/your_id
android:id="#+id/list"
use the notation #+ to add new id
Change the following -- android:id="#+id/list"
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
Now following will detect the list-
ListView lv=(ListView)findViewById(R.id.list);
If you want to refer Android resources , which are already defined in Android system, with #android:id/.. while to access resources that you have defined/created in your project, you use #id/.
Check this SO -- Difference between "#id/" and "#+id/" in Android
So for your case, you can also define list view by android:id="#android:id/list"
Also you can check this so Android: id list view
Using #id/android:list is for referencing the default list in a ListActivity.
You could change your Activity to a ListActivity and reference the ListView in your activity code with the getListView() method. For example:
public class Custom extends ListActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.custom);
ListView lv = getListView();
}
}
Alternatively as others have suggested you could use:
android:id="#+id/list"
Instead of:
android:id="#id/android:list"
My app uses a button which when clicked goes to a new activity which displays a list view. All of this seems to be working fine. But the list view is displayed on top of the same activity with the button. It is not displayed separately. So i see the main activity in the background and the overlapped listview! Can this problem be solved? My code is as follows:
Button CLick event:
view.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(Assignments.this, ViewEntry.class);
startActivity(i);
}
});
And the listview code:
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//setContentView(R.layout.database_view);
//ListView lv = (ListView)findViewById(R.id.listView1);
dbControl = new DatabaseControl(ViewEntry.this);
dbControl.open();
ArrayList<String> data = dbControl.getData();
if (data.equals(null)) {
Toast.makeText(ViewEntry.this, "Database Empty!", Toast.LENGTH_LONG)
.show();
} else {
final Dialog notice = new Dialog(this);
final TextView msgbox = new TextView(this);
//ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,data);
setListAdapter(new ArrayAdapter<String>(ViewEntry.this,
android.R.layout.simple_list_item_1, data));
final ListView listView = getListView();
//lv.setAdapter(arrayAdapter);
//lv.setTextFilterEnabled(true);
}
}
My xml code is as follows. But i don't think it makes a difference since i haven't used the setContentView. Using setContentView(R.layout.database_view); returns a debug error.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:background="#000000"
android:fadingEdge="vertical"
android:orientation="vertical" >
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true">
</ListView>
<TextView
android:id="#+id/textViewDatabase"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""/>
Thanks in advance!
Change background color of second activity layout to non-transparent. When you start second Activity the first is paused and goes into background but is still there like when dialog is shown.
Edit:
Activity is not transparent by default, check if you have properly defined appTheme in styles.xml and make sure you don't use android:theme="#android:style/Theme.Translucent" or "#00XXXXXX" color anywhere in your styles or manifest file.
If there is everything OK with styles then I don't know why your ListActivity is still transparent but you can change this by setting following layout as contentView:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ad_catalog_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#888888" <!-- example non-transparent color -->
android:orientation="vertical" >
<ListView
android:id="#android:id/list" <!-- has to be #android:id/list for ListActivity -->
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
</LinearLayout>
or by setting ListView background color:
getListView().setBackgroundColor(Color.rgb(xxx, xxx, xxx));
Instead of using transparent background color try using non transparent colors
try below code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:background="#b3b3b3"
android:fadingEdge="vertical"
android:orientation="vertical" >
Use an Intent to go to the other activity and create a list view itself in the new activity.
Use the Button to trigger the intent.
I have a listview in my code and I want to set adapter on it.
But the issue is, even after initializing the listview, it is still null resulting into nullPointerException. (I checked it by logging and debugging)
I'm not able to access any view from that xml.
What am I missing? Any help appreciated.
xml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:scrollbars="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ListView
android:id="#+id/lvToday"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:divider="#FFF"
android:dividerHeight="2dp" />
<ListView
android:id="#+id/lvTomorrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/lvToday"
android:divider="#FFF"
android:dividerHeight="2dp" />
</RelativeLayout>
</ScrollView>
Activity file
public class DashboardActivity extends Activity {
ListView lvToday, lvTomorrow;
TextView lblCall;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dashboard);
init();
}
private void init() {
lvToday = (ListView) findViewById(R.id.lvToday);
lvTomorrow = (ListView) findViewById(R.id.lvTomorrow);
TodayAppAdapter adapter = new TodayAppAdapter(DashboardActivity.this,
DashboardActivity.this);
// This line is giving NULL
lvToday.setAdapter(adapter);
TomorrowAppAdapter adapter1 = new TomorrowAppAdapter(
DashboardActivity.this, DashboardActivity.this);
// This line is giving NULL
lvTomorrow.setAdapter(adapter1);
}
}
1) test eclipse menu: Project -> Clean...
2) if you have more than one version for your xml layout (example layout-large, layout-xlarge,...), check if all of them have your view.
You are missing a TextView in your layout
Put a String []
along with name of your Adapter in your
OnDraw()
Method
I almost spent 72 hours trying to find a way to put a small description as well as an icon in my listview. I couldn't find a way to so I thought I should ask for your help. This is my xml.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/lvdaysInWeek"
android:padding="10dp"
android:textSize="20sp" />
</LinearLayout>
And my Java looked something like this
public class Schedule extends ListActivity{
ListView daysInWeek;
String myList[] = {"Monday","Tuesday", "Wednesday",
"Thursday","Friday","Saturday","Sunday"};
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.schedule);
daysInWeek = (ListView) findViewById(R.id.lvdaysInWeek);
daysInWeek.setAdapter(new ArrayAdapter<String>
(this,android.R.layout.simple_list_item_1,myList));
}
Please tell me how I can add an icon and a small description below the main text in the lisview.
Thanks in advance.
You will need a custom adapter.
This example shows you how.