GoogleMap-Android - Android Software Development

Hi all,
I am trying to get map in android Emulator, But I have error message when i run the application.How to rectify this error?
My Code:
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.googlemapsandroid"
android:versionCode="1"
android:versionName="1.0">
<uses-library android:name="com.google.android.maps.map" />
<application android:icon="@drawable/worldmap" android:label="@string/app_name">
<activity android:name=".GoogelMapsAndroid"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>
main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainlayout"
androidrientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.google.android.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="0ubDx0zU6vaeSSZoV0oyPB4zi7y8T2hKSZfAyZw"
/>
</RelativeLayout>
GoogleMapsAndroid.java
package com.android.googlemapsandroid;
import android.os.Bundle;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
public class GoogleMapsAndroid extends MapActivity
{
MapView mapview;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapview=(MapView)findViewById(R.id.mapview);
mapview.setSatellite(true);
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
I have error message:
java lang Runtime Exception Unable to instantiate ComponentInfo{com.android.googlemapsandroid/com.android.googlemapsandroid.MapsActivity}java.lang.RuntimeException: stub

Do you use Google APIs target in an emulator?

No. How to use Google api.

dineshsubramanian said:
No. How to use Google api.
Click to expand...
Click to collapse
This is what I mean:
http://img40.imageshack.us/f/screenshotcreatenewandr.png/

Thanks for your reply.
I will try in Google Api.

Now i ran in google api. but i have error message
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.googlemapdemo/com.googledemo.GoogleMapDemo}: android.view.InflateException: Binary XML file line #6: Error inflating class com.google.android.maps.MapView.

Related

[Q] MapView-No Map Display

I am new to SW development with Android.
Trying to have a MapView object in my display. Code is straightforward below. But for some reason when i launch the application i do not see any map but rather the grey grid.
I have looked at many posts on the internet and i understand that it is either an INTERNET permission (which is included in my coe) or a wrong apiKey. I have gone through the apiKey several time.
Am not sure what can be wrong. Any help would be great. Thanks, Lebnen.
-----------------------------------------------
Manifest.xml
-----------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.testmap"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
<uses-library android:name="com.google.android.maps" />
<uses-permission android:name="android.permission.INTERNET" />
<activity android:name=".TestMapActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
-----------------------------------------------
main.xml
-----------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainlayout"
androidrientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
>
<com.google.android.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:enabled="true"
android:apiKey="0SA_n7tIj-klgGxARuFJgEos8FBGtEshpgmfogA"
/>
</LinearLayout>
-----------------------------------------------
testMapActivity.java
-----------------------------------------------
package com.test.testmap;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.LinearLayout;
import com.google.android.maps.MapView;
import com.google.android.maps.MapController;
import com.google.android.maps.MapActivity;
import com.google.android.maps.GeoPoint;
public class TestMapActivity extends MapActivity {
private MapView mapView;
LinearLayout linearLayout;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
mapView = (MapView) this.findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
mapView.setSatellite(true);
}
@Override
public boolean isRouteDisplayed() { return false; }
}
Dont see your manifest. Is it a dev map key ? Is the application debuggable in the manifest ?
Sent from my Nexus One using XDA App
1. What do you mean by dev map key? Am using the debug.keystory MD5 hash that I feed into the google page http://code.google.com/android/add-ons/google-apis/maps-api-signup.html to get the apiKey.
2. The application is debbugable in the manifest.
Ok i see your files on computer now (not on android application on my nexus one)
replace com.google.android.maps.MapView by com.test.testmap.testMapActivity
If I replace it in main.xml the application crashes; in the manifest it does not compile
Help!
the:
<uses-permission android:name="android.permission.INTERNET" />
you have to put on <manifest>, not on <application>
like
<manifest ...>
<application ...>
<uses-library android:name="com.google.android.maps" />
.
.
.
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
Other thing that I'm not totally right if it's correct:
I don't know if this is correct, but for me, only worked when I create a new Android Project with Target on Google API's. Didn't work with Android 2.2 + map.jar.
Did you create with Android X.X or Google API ?
I have tried to put the INTERNET permission inside and outside the application. It does not make a difference.
I am building a Google API application.
It worked.
Weird. I had to add
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
in <manifest> outside of <application> and did it through the "Permissions" tab in Eclipse.
Thanks.
Interesting, because I thought that the "ACCESS_FINE_LOCAT ION" is used only when you try to use something with location, such as get location, distance between locations, etc..., I thought that it's not necessary when you only want to show the map
Good to know, thank you

[Q] unable to switch activity

Hi,
I am new to android development. I am facing problem in switching between activities. I am attaching the code files ... Please help me solve this problem
Being a new user the Forum doesn't allow me to write atTheRateSign in my message ... I am replacing it with % sign. Please don't confuse it.
Main Activity:
Code:
package swz.pkg;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class SWMainActivity extends Activity {
/** Called when the activity is first created. */
%Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btnMSrch = (Button) findViewById(R.id.btnClosetSearch);
try{
btnMSrch.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent myIntent = new Intent(v.getContext(),ClosetSearchAct.class);
startActivityForResult(myIntent,0);
}
});
}
catch (Exception ex)
{
System.out.println("---------------------******------------------------");
ex.printStackTrace();
System.out.println();
System.out.println("---------------------******------------------------");
}
}
}
main.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="%+id/widget0"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="ht ... android"
>
<Button
android:id="%+id/btnMeasurementSearch"
android:layout_width="fill_parent"
android:layout_height="150px"
android:background="#ffffffff"
android:text="Measurement Search"
android:textSize="26sp"
android:typeface="serif"
android:textStyle="bold"
android:textColor="#ff8c2528"
android:layout_x="0px"
android:layout_y="47px"
>
</Button>
<Button
android:id="%+id/btnClosetSearch"
android:layout_width="fill_parent"
android:layout_height="150px"
android:text="Closet Search"
android:textSize="26sp"
android:typeface="serif"
android:textStyle="bold"
android:textColor="#ff462556"
android:layout_x="0px"
android:layout_y="213px"
>
</Button>
</AbsoluteLayout>
closetSearch activity(The next activity I want to move to):
Code:
package swz.pkg;
import android.app.Activity;
import android.os.Bundle;
public class ClosetSearchAct extends Activity {
public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.closetsearchact);
}
}
closetsearchact.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="%+id/widget1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="ht .... android"
>
<Spinner
android:id="%+id/spinner1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_x="0px"
android:layout_y="33px"
>
</Spinner>
<Spinner
android:id="%+id/spinner2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_x="0px"
android:layout_y="101px"
>
</Spinner>
<Spinner
android:id="%+id/spinner3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_x="0px"
android:layout_y="173px"
>
</Spinner>
<ImageButton
android:id="%+id/btnReg"
android:layout_width="128px"
android:layout_height="wrap_content"
android:src="%drawable/reg"
android:layout_x="151px"
android:layout_y="279px"
>
</ImageButton>
<ImageButton
android:id="%+id/btnSearch"
android:layout_width="114px"
android:layout_height="49px"
android:src="%drawable/search"
android:layout_x="37px"
android:layout_y="279px"
>
</ImageButton>
</AbsoluteLayout>
AndroidManifest.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="ht ... android"
package="swz.pkg"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="%drawable/icon" android:label="%string/app_name">
<activity android:name=".SWMainActivity"
android:label="%string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ClosetSearchAct" android:label="%string/app_name"> </activity>
</application>
</manifest>

[NEWBIE] Intents not working properly..

Hey there. i was experimenting with intents.. While I got stuck in this bug. I am almost positive, that my java classes have been coded correctly...
I think, its the android manifest.. The intent filters have not been setup correctly... However I will be posting.. all of my code and the logcat here...
Please help me.. Thanks in advance!
Manifest.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.intents"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.intents.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.intents.SecondActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.SecondActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
activity_xml.xml
Code:
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:layout_width = "fill_parent"
android:layout_height="wrap_content"
android:text="Click for second Activity"
android:onClick="onClick"
android:id="@+id/button1"
/>
</RelativeLayout>
second_act.xml
Code:
<?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" >
<TextView
android:id="@+id/tvSecond"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Enter your name! " />
<Button
android:id="@+id/logOn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hit to Login"
android:onClick = "onClick" />
</LinearLayout>
MainActivity.java
Code:
package com.example.intents;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends Activity {
int request_Code = 1;
/** Called when the activity is first created. */
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClick(View v) {
Intent i = new Intent("com.example.intents.MainActivity");
i.putExtra("str1", "This is str1");
i.putExtra("age1", 16);
Bundle ex = new Bundle();
ex.putString("str2", "this is str2 and a bundle String");
ex.putInt("age2", 22);
i.putExtras(ex);
startActivityForResult(i, 1);
}
protected void onActivityResult(int requestCode, int ResultCode, Intent data) {
if (requestCode == 1) {
if (ResultCode == RESULT_OK) {
Toast.makeText(this,
Integer.toString(data.getIntExtra("age3", 0)),
Toast.LENGTH_SHORT).show();
Toast.makeText(this, data.getData().toString(),
Toast.LENGTH_LONG).show();
}
}
}
}
SecondActivity.xml
Code:
package com.example.intents;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class SecondActivity extends Activity {
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.second_act);
Toast.makeText(this, getIntent().getStringExtra("str1"),
Toast.LENGTH_SHORT).show();
Toast.makeText(this, getIntent().getIntExtra("age1", 0),
Toast.LENGTH_SHORT).show();
Bundle bundle = getIntent().getExtras();
Toast.makeText(this, bundle.getString("str2"), Toast.LENGTH_SHORT)
.show();
Toast.makeText(this, Integer.toString(bundle.getInt("age2")),
Toast.LENGTH_SHORT).show();
}
public void onClick(View v) {
Intent i = new Intent();
i.putExtra("age3", 45);
i.setData(Uri.parse("Something has been passed to main aactivity"));
setResult(RESULT_OK, i);
finish();
}
}
Logcat[only the portion highlighted in red! ]
Uploaded here, for a better view..
hiphop12ism said:
Hey there. i was experimenting with intents.. While I got stuck in this bug. I am almost positive, that my java classes have been coded correctly...
I think, its the android manifest.. The intent filters have not been setup correctly... However I will be posting.. all of my code and the logcat here...
Please help me.. Thanks in advance!
Click to expand...
Click to collapse
OK, so first of all, in your manifest, you do not need to create an intent-filter, that is just if an activity needs to be launched from another application.
Then, when you create your Intent to start the SecondActivity, do it like this:
Code:
Intent i = new Intent(this, SecondActivity.class);
// put extras and startforResult here
The Error in the logcat states that it could not find the activity, so I suppose this is why
Code:
<activity
android:name="com.example.intents.SecondActivity"
android:label="@string/app_name" >
<intent-filter>
[B]<action android:name="[COLOR="Red"]android.intent.action.SecondActivity[/COLOR]" />[/B]
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
The bold should be referencing the same intent you are trying to call. Change the red text portion above to "com.example.intents.SecondActivity" and use the same to call the intent.
example: Intent i = new Intent("com.example.intents.SecondActivity");
The red text should match each other.
Still crashing!
zalez said:
Code:
<activity
android:name="com.example.intents.SecondActivity"
android:label="@string/app_name" >
<intent-filter>
[B]<action android:name="[COLOR="Red"]android.intent.action.SecondActivity[/COLOR]" />[/B]
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
The bold should be referencing the same intent you are trying to call. Change the red text portion above to "com.example.intents.SecondActivity" and use the same to call the intent.
example: Intent i = new Intent("com.example.intents.SecondActivity");
The red text should match each other.
Click to expand...
Click to collapse
I changed the code, as you said.. But it is still not working...
I am uploading the manifest, and the MainActivity.java again..
Mainfest:
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.intents"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.intents.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.intents.SecondActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.intents.SecondActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.java
Code:
package com.example.intents;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends Activity {
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClick(View v) {
Intent i = new Intent("com.example.intents.SecondActivity");
i.putExtra("str1", "This is str1");
i.putExtra("age1", 16);
Bundle ex = new Bundle();
ex.putString("str2", "this is str2 and a bundle String");
ex.putInt("age2", 22);
i.putExtras(ex);
startActivityForResult(i, 1);
}
protected void onActivityResult(int requestCode, int ResultCode, Intent data) {
if (requestCode == 1) {
if (ResultCode == RESULT_OK) {
Toast.makeText(this,
Integer.toString(data.getIntExtra("age3", 0)),
Toast.LENGTH_SHORT).show();
Toast.makeText(this, data.getData().toString(),
Toast.LENGTH_LONG).show();
}
}
}
}
It is giving errors because of how you are trying to get the strings from the intent in SecondActivity.
replace what you have in your SecondActivity onCreate with the below.
Code:
Intent intent = getIntent();
Toast.makeText(this, intent.getStringExtra("str1"), Toast.LENGTH_LONG).show();
Toast.makeText(this, String.valueOf(intent.getIntExtra("age1", 0)), Toast.LENGTH_LONG).show();
Bundle bundle = intent.getExtras();
Toast.makeText(this, bundle.getString("str2"), Toast.LENGTH_SHORT)
.show();
Toast.makeText(this, Integer.toString(bundle.getInt("age2")),
Toast.LENGTH_SHORT).show();
Thank you, finally it worked :thumbup:
Sent from my GT-S6102 using xda app-developers app

[Q] ListView with BaseAdapter not showing

Hi I have used ListFragment and simple ArrayAdapter quite often. And now I want to try some more by customizing BaseAdapter. But something happened, the List is not showing at all. I don't have any error (the Logcat also saying there're no error). But I debug it, and found out that getView() in my customized BaseAdapter is not called. I wonder why?
Here's the snippet:
#favorite_list_layout
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<ListView
android:id="@+id/favorite_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
#favorite_list_item
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/favorite_text"
android:layout_margin="5dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="0dp"
android:textSize="35sp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/favorite_text_details"
android:layout_marginLeft="10dp"
android:layout_marginTop="0dp"
android:layout_marginBottom="5dp"
android:fontFamily="sans-serif-light"
android:textSize="18sp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
#FavoritesFragment
Code:
public class FavoritesFragment extends ListFragment {
[user=439709]@override[/user]
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
//... setting variable favList, and this code is working. favList is not empty and there're no error
setListAdapter(new FavoriteAdapter(getActivity(), favList));
}
}
FavoriteAdapter, extends BaseAdapter
Code:
public class FavoriteAdapter extends BaseAdapter {
private Context ctx;
List<DMapData> list;
public FavoriteAdapter(Context context, List<DMapData> list) {
this.ctx = context;
this.list = list;
System.out.println("constructor executed!");
}
[user=439709]@override[/user]
public int getCount() {
return list.size();
}
[user=439709]@override[/user]
public Object getItem(int i) {
return list.get(i);
}
[user=439709]@override[/user]
public long getItemId(int i) {
return i;
}
[user=439709]@override[/user]
public View getView(int position, View convertView, ViewGroup parent) {
System.out.println("GetView is executed"); //But it's not.
View rowView = convertView;
if (rowView == null) {
LayoutInflater inflater = (LayoutInflater) ctx
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView = inflater.inflate(R.layout.favorite_list_item, parent, false);
}
TextView favText = (TextView) rowView.findViewById(R.id.favorite_text);
TextView detailsText = (TextView) rowView.findViewById(R.id.favorite_text_details);
DMapData data = list.get(position);
System.out.println("DMapData from List");
favText.setText(data.getName());
detailsText.setText(data.getDetails().length()<=50? data.getDetails() : data.getDetails().substring(0, 51).concat("..."));
System.out.println("At the end of getView()");
return rowView;
}
}
Thanks
The id of the ListView has to be a special one so that the ListFragment can find it:
Code:
android:id="@android:id/list"
Hmm...
I have tried to change the id like your code. But, still not shown up. Is there anything I should do with my ListFragment?
nikwen said:
The id of the ListView has to be a special one so that the ListFragment can find it:
Code:
android:id="@android:id/list"
Click to expand...
Click to collapse
JoshieGeek said:
Hmm...
I have tried to change the id like your code. But, still not shown up. Is there anything I should do with my ListFragment?
Click to expand...
Click to collapse
Do you inflate your layout?
Code:
[user=439709]@override[/user]
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_layout, container, false);
}
I always set the adapter in onCreate but there shouldn't be a difference.
Your layout looks like that now, right?
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<ListView
android:id="android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
EDIT: Oh, add an orientation to the LinearLayout or replace it by a RelativeLayout.
And change the ListView heigth to match_parent.
Yupz. But still no different.
Here's my changed code. I have changed not using my customized adapter again, but instead using SimpleAdapter.
/res/layout/favorite_list_layout.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
/res/layout/favorite_list_item
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/favorite_text"
android:layout_margin="5dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="0dp"
android:textSize="35sp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/favorite_text_details"
android:layout_marginLeft="10dp"
android:layout_marginTop="0dp"
android:layout_marginBottom="5dp"
android:fontFamily="sans-serif-light"
android:textSize="18sp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
/src/.../AllFragment.java
Code:
public class AllFragment extends ListFragment {
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//TODO get All Data
//Let's just adopt Favorite List Adapter for now
MasterDataReader mdReader = new MasterDataReader();
mdReader.execute();
List<DMapData> allList = new ArrayList<DMapData>();
allList.add(new DMapData("Empty", "No data found!"));
try {
allList = mdReader.get();
System.out.println("All List received");
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
List<Map<String, String>> finList = new ArrayList<Map<String, String>>();
for(DMapData data : allList) {
Map<String, String> m = new HashMap<String, String>();
m.put("name", data.getName());
m.put("detail", data.getDetails().length()<=50? data.getDetails() : data.getDetails().substring(0, 51).concat("..."));
finList.add(m);
}
String[] colNames = new String[] {
"name", "detail"
};
int[] tView = new int[] {
R.id.favorite_text, R.id.favorite_text_details
};
SimpleAdapter simpleAdapter = new SimpleAdapter(getActivity(), finList, R.layout.favorite_list_layout,
colNames, tView);
setListAdapter(simpleAdapter);
}
[user=439709]@override[/user]
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.favorite_list_layout, container, false);
}
}
What do you think?
nikwen said:
Do you inflate your layout?
Code:
[user=439709]@override[/user]
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_layout, container, false);
}
I always set the adapter in onCreate but there shouldn't be a difference.
Your layout looks like that now, right?
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<ListView
android:id="android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
EDIT: Oh, add an orientation to the LinearLayout or replace it by a RelativeLayout.
And change the ListView heigth to match_parent.
Click to expand...
Click to collapse
JoshieGeek said:
Yupz. But still no different.
Here's my changed code. I have changed not using my customized adapter again, but instead using SimpleAdapter.
/res/layout/favorite_list_layout.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
/res/layout/favorite_list_item
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/favorite_text"
android:layout_margin="5dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="0dp"
android:textSize="35sp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/favorite_text_details"
android:layout_marginLeft="10dp"
android:layout_marginTop="0dp"
android:layout_marginBottom="5dp"
android:fontFamily="sans-serif-light"
android:textSize="18sp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
/src/.../AllFragment.java
Code:
public class AllFragment extends ListFragment {
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//TODO get All Data
//Let's just adopt Favorite List Adapter for now
MasterDataReader mdReader = new MasterDataReader();
mdReader.execute();
List<DMapData> allList = new ArrayList<DMapData>();
allList.add(new DMapData("Empty", "No data found!"));
try {
allList = mdReader.get();
System.out.println("All List received");
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
List<Map<String, String>> finList = new ArrayList<Map<String, String>>();
for(DMapData data : allList) {
Map<String, String> m = new HashMap<String, String>();
m.put("name", data.getName());
m.put("detail", data.getDetails().length()<=50? data.getDetails() : data.getDetails().substring(0, 51).concat("..."));
finList.add(m);
}
String[] colNames = new String[] {
"name", "detail"
};
int[] tView = new int[] {
R.id.favorite_text, R.id.favorite_text_details
};
SimpleAdapter simpleAdapter = new SimpleAdapter(getActivity(), finList, R.layout.favorite_list_layout,
colNames, tView);
setListAdapter(simpleAdapter);
}
[user=439709]@override[/user]
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.favorite_list_layout, container, false);
}
}
What do you think?
Click to expand...
Click to collapse
Try this layout:
Code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@android:id/list"
android:layout_alignParentTop="true"
android:fastScrollEnabled="true" />
<ProgressBar
android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
style="?android:attr/progressBarStyle" />
</RelativeLayout>
It's working for me.
Did you try to write all entries to the logs? Do you get an output?
You know what? This is really make me laugh all the time, that it's because what I think is right but actually not. The list that I provided for my ListView is actually empty. Your layout tell me, because there's always the progressbar. Thank you very much for your help. :highfive:
nikwen said:
Try this layout:
Code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@android:id/list"
android:layout_alignParentTop="true"
android:fastScrollEnabled="true" />
<ProgressBar
android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
style="?android:attr/progressBarStyle" />
</RelativeLayout>
It's working for me.
Did you try to write all entries to the logs? Do you get an output?
Click to expand...
Click to collapse
JoshieGeek said:
You know what? This is really make me laugh all the time, that it's because what I think is right but actually not. The list that I provided for my ListView is actually empty. Your layout tell me, because there's always the progressbar. Thank you very much for your help. :highfive:
Click to expand...
Click to collapse
Welcome.
I'm glad that you solved that because it began to drive me crazy. :laugh:
@JoshieGeek
consider using Log
Log.i("class/functionName","message you want to display");
Click to expand...
Click to collapse
It will be easy to debug
Sandeep_Jagtap said:
@JoshieGeek
consider using Log
It will be easy to debug
Click to expand...
Click to collapse
Didn't you see that he already solved his problem?
nikwen said:
Didn't you see that he already solved his problem?
Click to expand...
Click to collapse
Yes its quite noticeable
As he was saying he could not see error in Log while debugging. My advice to use log was for his future projects.
Sent from my Incredible S using xda app-developers app
Sandeep_Jagtap said:
Yes its quite noticeable
As he was saying he could not see error in Log while debugging. My advice to use log was for his future projects.
Sent from my Incredible S using xda app-developers app
Click to expand...
Click to collapse
OK.
Check out my guide on debugging here: http://forum.xda-developers.com/showthread.php?t=2325164

Widget not working

Hey, fellas.. I was learning about widgets. But I got stuck at the very beginning. I was trying to make the simplest of a widget. Firstly, I made an app, that only has one textview on it. When clicked , it shows the number of times it has been clicked. Then I tried to make a widget of the same.
But when I click over the widget, nothing happens. It just shows the initialized number '0'. The debugging goes fine. There is no ANR errors.
But I am not able to figure out the logical error. As the debugging goes alright, I don't think, the logcat will be necessary.
However, If required , I will provide it too. For now, I am uploading the AppWidget.class, widget.xml, manifest.xml, widget_provider.xml :::
THE APPWIDGET.CLASS:
Code:
package com.example.increment;
import android.app.IntentService;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.widget.RemoteViews;
public class AppWidget extends AppWidgetProvider {
int c = 0;
[user=439709]@override[/user]
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if (intent.getAction() == null)
context.startService(new Intent(context, ToggleService.class));
else
super.onReceive(context, intent);
}
[user=439709]@override[/user]
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
// TODO Auto-generated method stub
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
private class ToggleService extends IntentService {
public ToggleService() {
super("AppWidget$ToggleService");
// TODO Auto-generated constructor stub
}
[user=439709]@override[/user]
protected void onHandleIntent(Intent intent) {
// TODO Auto-generated method stub
ComponentName me = new ComponentName(this, AppWidget.class);
AppWidgetManager mgr = AppWidgetManager.getInstance(this);
mgr.updateAppWidget(me, buildUpdate(this));
}
private RemoteViews buildUpdate(Context context) {
// TODO Auto-generated method stub
RemoteViews rm = new RemoteViews(context.getPackageName(),
R.layout.widget);
c++;
String s = String.valueOf(c);
rm.setTextViewText(R.id.t2, s);
Intent i = new Intent(this, AppWidget.class);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
rm.setOnClickPendingIntent(R.id.t2, pi);
return rm;
}
}
}
THE WIDGET.XML
Code:
<?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" >
<TextView
android:id="@+id/t2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:clickable="true" />
</LinearLayout>
THE WIDGET_PROVIDER.XML:
Code:
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minHeight="100sp"
android:minWidth="100sp"
android:updatePeriodMillis="1000"
android:initialLayout="@layout/widget">
</appwidget-provider>
THE MANIFEST.XML:
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.increment"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.increment.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name="com.example.increment.AppWidget"
android:icon="@drawable/ic_launcher"
android:label="tanmay" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/widget_provider" />
</receiver>
<service android:name=".AppWidget$ToggleService" >
</service>
</application>
</manifest>
Thanks in advance..

Categories

Resources