Android fragments backward compatibility - android

I am trying to do a android application where we need to use the fragments. I am following the rule while i am doing with backward compatibility. i.e. Extends FragmentActivity instead of Activity and i use the use the getSupportFragmentManager() also. The same code working with 4.1 but not working with 2.2 .
i using the
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
String newTime = String.valueOf(System.currentTimeMillis());
DetailFragment fragment = (DetailFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.detailFragment);
if (fragment != null && fragment.isInLayout()) {
fragment.setText(newTime);
} else {
Intent intent = new Intent(getActivity().getApplicationContext(), DetailActivity.class);
intent.putExtra("value", newTime);
startActivity(intent);
Can any one help ? i am getting the force close. that unable start the activity component info.
it's showing error at setContentView() main activity ,which contains the framents .
<?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="horizontal" >
<fragment
android:id="#+id/listFragment"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:layout_marginTop="?android:attr/actionBarSize"
class="com.example.fragmentsample.MyListFragment" ></fragment>
<fragment
android:id="#+id/detailFragment"
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="match_parent"
class="com.example.fragmentsample.DetailFragment" >
<!-- Preview: layout=#layout/details -->
</fragment>
</LinearLayout>
logcat:
10-03 16:03:54.586: E/AndroidRuntime(649): FATAL EXCEPTION: main
10-03 16:03:54.586: E/AndroidRuntime(649): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.fragmentsample/com.example.fragmentsample.RssfeedActivity}: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x2
10-03 16:03:54.586: E/AndroidRuntime(649): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
10-03 16:03:54.586: E/AndroidRuntime(649): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
10-03 16:03:54.586: E/AndroidRuntime(649): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
10-03 16:03:54.586: E/AndroidRuntime(649): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
10-03 16:03:54.586: E/AndroidRuntime(649): at android.os.Handler.dispatchMessage(Handler.java:99)
10-03 16:03:54.586: E/AndroidRuntime(649): at android.os.Looper.loop(Looper.java:123)
10-03 16:03:54.586: E/AndroidRuntime(649): at android.app.ActivityThread.main(ActivityThread.java:3683)
10-03 16:03:54.586: E/AndroidRuntime(649): at java.lang.reflect.Method.invokeNative(Native Method)
10-03 16:03:54.586: E/AndroidRuntime(649): at java.lang.reflect.Method.invoke(Method.java:507)
10-03 16:03:54.586: E/AndroidRuntime(649): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-03 16:03:54.586: E/AndroidRuntime(649): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-03 16:03:54.586: E/AndroidRuntime(649): at dalvik.system.NativeStart.main(Native Method)
10-03 16:03:54.586: E/AndroidRuntime(649): Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x2
10-03 16:03:54.586: E/AndroidRuntime(649): at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:463)
10-03 16:03:54.586: E/AndroidRuntime(649): at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:3692)
10-03 16:03:54.586: E/AndroidRuntime(649): at android.widget.LinearLayout$LayoutParams.<init>(LinearLayout.java:1400)
10-03 16:03:54.586: E/AndroidRuntime(649): at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:1326)
10-03 16:03:54.586: E/AndroidRuntime(649): at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:47)
10-03 16:03:54.586: E/AndroidRuntime(649): at android.view.LayoutInflater.rInflate(LayoutInflater.java:625)
10-03 16:03:54.586: E/AndroidRuntime(649): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
10-03 16:03:54.586: E/AndroidRuntime(649): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
10-03 16:03:54.586: E/AndroidRuntime(649): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
10-03 16:03:54.586: E/AndroidRuntime(649): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
10-03 16:03:54.586: E/AndroidRuntime(649): at android.app.Activity.setContentView(Activity.java:1657)
10-03 16:03:54.586: E/AndroidRuntime(649): at com.example.fragmentsample.RssfeedActivity.onCreate(RssfeedActivity.java:10)
10-03 16:03:54.586: E/AndroidRuntime(649): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-03 16:03:54.586: E/AndroidRuntime(649): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
10-03 16:03:54.586: E/AndroidRuntime(649): ... 11 more

In your XML file you need to supply the full path to Fragment:
<android.support.v4.app.Fragment
android:id="#+id/detailFragment"
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="match_parent"
class="com.example.fragmentsample.DetailFragment" >
<!-- Preview: layout=#layout/details -->
</android.support.v4.app.Fragment>

Related

App crashes when instantiating HelpStackSDK

We tried integrating HelpStack by following steps given on GitHub, but we kept getting the following errors:
04-03 13:54:22.054 4638-4638/com.playerline.android E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.playerline.android/com.tenmiles.helpstack.activities.HomeActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
at android.app.ActivityThread.access$600(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4448)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.tenmiles.helpstack.activities.HSActivityParent.onCreate(HSActivityParent.java:48)
at com.tenmiles.helpstack.activities.HomeActivity.onCreate(HomeActivity.java:46)
at android.app.Activity.performCreate(Activity.java:4465)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
at android.app.ActivityThread.access$600(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4448)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
I'm guessing it has something to do with the App Theme, which in our case is is Theme.AppCompat.NoActionBar.

NullPointer exception when using ListView

I've got following code, which gets launched as a second activity:
public class SensorActivity extends Activity implements SensorEventListener{
List<Sensor> sensors;
Sensor selectedSens;
SensorManager SensMng;
ArrayAdapter<String> adapter;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sensor);
final ListView listSensors = (ListView) findViewById(R.id.listvalues);
SensMng = (SensorManager) getSystemService(SENSOR_SERVICE);
sensors = SensMng.getSensorList(Sensor.TYPE_ALL);
ArrayAdapter<Sensor> adapter = new ArrayAdapter<Sensor>(this, android.R.layout.simple_list_item_1, sensors);
listSensors.setAdapter(adapter);
}
Here's my XML file:
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/listvalues"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
I keep on getting a nullpointer exception:
10-03 21:46:57.475: E/AndroidRuntime(9893): FATAL EXCEPTION: main
10-03 21:46:57.475: E/AndroidRuntime(9893): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{ch.ethz.inf.vs.android.spurra.sensors/ch.ethz.inf.vs.android.spurra.sensors.SensorActivity}: java.lang.NullPointerException
10-03 21:46:57.475: E/AndroidRuntime(9893): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2024)
10-03 21:46:57.475: E/AndroidRuntime(9893): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
10-03 21:46:57.475: E/AndroidRuntime(9893): at android.app.ActivityThread.access$600(ActivityThread.java:140)
10-03 21:46:57.475: E/AndroidRuntime(9893): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
10-03 21:46:57.475: E/AndroidRuntime(9893): at android.os.Handler.dispatchMessage(Handler.java:99)
10-03 21:46:57.475: E/AndroidRuntime(9893): at android.os.Looper.loop(Looper.java:137)
10-03 21:46:57.475: E/AndroidRuntime(9893): at android.app.ActivityThread.main(ActivityThread.java:4898)
10-03 21:46:57.475: E/AndroidRuntime(9893): at java.lang.reflect.Method.invokeNative(Native Method)
10-03 21:46:57.475: E/AndroidRuntime(9893): at java.lang.reflect.Method.invoke(Method.java:511)
10-03 21:46:57.475: E/AndroidRuntime(9893): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
10-03 21:46:57.475: E/AndroidRuntime(9893): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
10-03 21:46:57.475: E/AndroidRuntime(9893): at dalvik.system.NativeStart.main(Native Method)
10-03 21:46:57.475: E/AndroidRuntime(9893): **Caused by**: java.lang.NullPointerException
10-03 21:46:57.475: E/AndroidRuntime(9893): at android.app.Activity.findViewById(Activity.java:1882)
10-03 21:46:57.475: E/AndroidRuntime(9893): at ch.ethz.inf.vs.android.spurra.sensors.SensorActivity.<init>(SensorActivity.java:24)
10-03 21:46:57.475: E/AndroidRuntime(9893): at java.lang.Class.newInstanceImpl(Native Method)
10-03 21:46:57.475: E/AndroidRuntime(9893): at java.lang.Class.newInstance(Class.java:1319)
10-03 21:46:57.475: E/AndroidRuntime(9893): at android.app.Instrumentation.newActivity(Instrumentation.java:1057)
10-03 21:46:57.475: E/AndroidRuntime(9893): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2015)
10-03 21:46:57.475: E/AndroidRuntime(9893): ... 11 more
All I did was really just copy past from my main activity, plus adjusting the values. The main activity works without any problems, this one however doesn't. I've tried cleaning, rebuilding the project, to no avail.
Can anyone please tell me whats wrong?
Thanks,
Regards
I've declared " final ListView listVals = (ListView) findViewById(R.id.listvalues);" as a field, so before running setContentView(). Once I've moved it into the actual function, it worked. So I assume that was causing it to return null?
Yes. If you call findViewById(R.id.someId); before calling setContentView(R.layout.someLayout); it will return null because you haven't yet inflated your layout which contains the View id you are trying to find.
Basically, your Views exist inside of your layout so if you try to use findViwById() before you inflate your layout (usually with setContentView()) then there is nothing to find. So you will get NPE when you try to use like when you call a function on it.
If your project has external jar files, go to Project->properties->order and export and select all external jar files. That should do the work.

Selecting an item in ListFragment list programmatically

I've made my Android app tablet optimized and I followed the tutorial here:
Everything is great, but I am trying to select an item (say, the 1st item) with a button in the ActionBar.
I tried this answer to use performItemClick but on I've got error reports of java.lang.IllegalStateException
in android.support.v4.app.ListFragment.ensureList, java.lang.IllegalStateException: Content view not yet created, and java.lang.NullPointerException
in android.content.ComponentName.<init>
I've tried checking if the ListView is null and still get the error reports on the Play Store. How do I properly select an item in my list programmatically?
Update to add logcat and the code is virtually identical to the tutorials in the links:
Logcat A:
java.lang.IllegalStateException: Content view not yet created
at android.support.v4.app.ListFragment.ensureList(ListFragment.java:328)
at android.support.v4.app.ListFragment.getListView(ListFragment.java:222)
at com.ccwilcox.meteorshower.MeteorList.showMeteorDetails(MeteorList.java:69)
at com.ccwilcox.meteorshower.MeteorList.onListItemClick(MeteorList.java:62)
at android.support.v4.app.ListFragment$2.onItemClick(ListFragment.java:58)
at android.widget.AdapterView.performItemClick(AdapterView.java:298)
at android.widget.AbsListView.performItemClick(AbsListView.java:1280)
at com.ccwilcox.meteorshower.MainActivity.viewUpcomingEvent(MainActivity.java:648)
at com.ccwilcox.meteorshower.MainActivity.onOptionsItemSelected(MainActivity.java:534)
at android.app.Activity.onMenuItemSelected(Activity.java:2606)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:361)
at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:1045)
at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
at com.android.internal.view.menu.ActionMenuView.invokeItem(ActionMenuView.java:592)
at com.android.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:149)
at android.view.View.performClick(View.java:4222)
at android.view.View$PerformClick.run(View.java:17273)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4895)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
at dalvik.system.NativeStart.main(Native Method)
Logcat B:
java.lang.NullPointerException
at android.content.ComponentName.<init>(ComponentName.java:75)
at android.content.Intent.<init>(Intent.java:2874)
at com.ccwilcox.meteorshower.MeteorList.showMeteorDetails(MeteorList.java:86)
at com.ccwilcox.meteorshower.MeteorList.onListItemClick(MeteorList.java:62)
at android.support.v4.app.ListFragment$2.onItemClick(ListFragment.java:58)
at android.widget.AdapterView.performItemClick(AdapterView.java:284)
at android.widget.ListView.performItemClick(ListView.java:3701)
at com.ccwilcox.meteorshower.MainActivity.viewUpcomingEvent(MainActivity.java:648)
at com.ccwilcox.meteorshower.MainActivity.onOptionsItemSelected(MainActivity.java:534)
at android.app.Activity.onMenuItemSelected(Activity.java:2205)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:361)
at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:779)
at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:861)
at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:532)
at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)
at android.view.View$PerformClick.run(View.java:9152)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Update 2
And here is the code that is causing the problem:
if (mListFragment.listView != null) {
mListFragment.listView.performItemClick(mListFragment.listView.getAdapter().getView(position, null, null), position, mListFragment.listView.getAdapter().getItemId(position));
}

Custom Pinch To Zoom View

I am trying to implement Pinch To Zoom on an Android app I am working on. For this, I have made a Java Class called PinchToZoom using the Android developer's website. However, if I try to launch my app I get an error in my XML file. I am confused as to why though, because I thought I had implemented it correctly. This is the XML code:
<LinearLayout 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:background="#222222"
android:orientation="vertical" >
<com.andriesse.athena.PinchToZoom
android:id="#+id/selectedImage"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:adjustViewBounds="true"
android:contentDescription="#string/content" />
</LinearLayout>
I hope you guys can help me out!
EDIT:
I forgot to add the error log before, so here it is:
10-03 13:35:40.207: E/AndroidRuntime(2421): FATAL EXCEPTION: main
10-03 13:35:40.207: E/AndroidRuntime(2421): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.andriesse.athena/com.andriesse.athena.ImageEditing}: android.view.InflateException: Binary XML file line #8: Error inflating class com.andriesse.athena.PinchToZoom
10-03 13:35:40.207: E/AndroidRuntime(2421): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
10-03 13:35:40.207: E/AndroidRuntime(2421): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
10-03 13:35:40.207: E/AndroidRuntime(2421): at android.app.ActivityThread.access$600(ActivityThread.java:127)
10-03 13:35:40.207: E/AndroidRuntime(2421): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
10-03 13:35:40.207: E/AndroidRuntime(2421): at android.os.Handler.dispatchMessage(Handler.java:99)
10-03 13:35:40.207: E/AndroidRuntime(2421): at android.os.Looper.loop(Looper.java:137)
10-03 13:35:40.207: E/AndroidRuntime(2421): at android.app.ActivityThread.main(ActivityThread.java:4441)
10-03 13:35:40.207: E/AndroidRuntime(2421): at java.lang.reflect.Method.invokeNative(Native Method)
10-03 13:35:40.207: E/AndroidRuntime(2421): at java.lang.reflect.Method.invoke(Method.java:511)
10-03 13:35:40.207: E/AndroidRuntime(2421): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-03 13:35:40.207: E/AndroidRuntime(2421): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-03 13:35:40.207: E/AndroidRuntime(2421): at dalvik.system.NativeStart.main(Native Method)
10-03 13:35:40.207: E/AndroidRuntime(2421): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class com.andriesse.athena.PinchToZoom
10-03 13:35:40.207: E/AndroidRuntime(2421): at android.view.LayoutInflater.createView(LayoutInflater.java:589)
10-03 13:35:40.207: E/AndroidRuntime(2421): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
10-03 13:35:40.207: E/AndroidRuntime(2421): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
10-03 13:35:40.207: E/AndroidRuntime(2421): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
10-03 13:35:40.207: E/AndroidRuntime(2421): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
10-03 13:35:40.207: E/AndroidRuntime(2421): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
10-03 13:35:40.207: E/AndroidRuntime(2421): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
10-03 13:35:40.207: E/AndroidRuntime(2421): at android.app.Activity.setContentView(Activity.java:1835)
10-03 13:35:40.207: E/AndroidRuntime(2421): at com.andriesse.athena.ImageEditing.onCreate(ImageEditing.java:26)
10-03 13:35:40.207: E/AndroidRuntime(2421): at android.app.Activity.performCreate(Activity.java:4465)
10-03 13:35:40.207: E/AndroidRuntime(2421): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
10-03 13:35:40.207: E/AndroidRuntime(2421): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
10-03 13:35:40.207: E/AndroidRuntime(2421): ... 11 more
10-03 13:35:40.207: E/AndroidRuntime(2421): Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet]
10-03 13:35:40.207: E/AndroidRuntime(2421): at java.lang.Class.getConstructorOrMethod(Class.java:460)
10-03 13:35:40.207: E/AndroidRuntime(2421): at java.lang.Class.getConstructor(Class.java:431)
10-03 13:35:40.207: E/AndroidRuntime(2421): at android.view.LayoutInflater.createView(LayoutInflater.java:561)
10-03 13:35:40.207: E/AndroidRuntime(2421): ... 22 more
This is the key line:
Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet]
Make sure that your custom listview has these constructors:
public PinchToZoom(Context context) {
this(context, null);
}
public PinchToZoom(Context context, AttributeSet attrs) { // <--- missing?
this(context, attrs, 0);
}
public PinchToZoom(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// initialisation code here
}
I've chained them this way so you never have to do anything except in the 3rd constructor. If you have these constructors, and they don't have external dependencies that can only be resolved at runtime, your custom listview will also preview correctly.
Instead of creating an xml node of type com.andriesse.athena.PinchToZoom, try creating one of type view and giving it a class attribute of class= "com.andriesse.athena.PinchToZoom", like this:
<LinearLayout 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:background="#222222"
android:orientation="vertical" >
<view
class="com.andriesse.athena.PinchToZoom"
android:id="#+id/selectedImage"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:adjustViewBounds="true"
android:contentDescription="#string/content" />
</LinearLayout>
EDIT: also, instead of writing your own pinch-zoom code, you may want to try using this: https://github.com/jasonpolites/gesture-imageview
I used it on a previous project and it worked great for me.

Android httpclient calling restfull web service

according to following url I have created a requesthelper for calling a restfull webservice(.Net).
http://as400samplecode.blogspot.com/2011/09/android-asynctask-httpclient-with.html
every time I call it from Android device it give error. in one of the topic at stackoverflow I suggest add '/' character at the end of the URL. You can find my url formats and given errors as listed below.
http://domain.com/default.svc/start/4ef8e420-e6a2-49f5-b612-c0b2dced0920/
at web browser it returns "End point not found".
from the Android Log :
10-03 18:02:07.373: WARN/HTTP1:(3983): Not Found
10-03 18:02:07.383: WARN/HTTP3:(3983): java.io.IOException: Not Found
10-03 18:02:07.383: WARN/HTTP3:(3983): at requestHelper.doInBackground(requestHelper.java:84)
10-03 18:02:07.383: WARN/HTTP3:(3983): at requestHelper.doInBackground(requestHelper.java:1)
10-03 18:02:07.383: WARN/HTTP3:(3983): at android.os.AsyncTask$2.call(AsyncTask.java:185)
10-03 18:02:07.383: WARN/HTTP3:(3983): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
10-03 18:02:07.383: WARN/HTTP3:(3983): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
10-03 18:02:07.383: WARN/HTTP3:(3983): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
10-03 18:02:07.383: WARN/HTTP3:(3983): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
10-03 18:02:07.383: WARN/HTTP3:(3983): at java.lang.Thread.run(Thread.java:1096)
http://domain.com/default.svc/start/4ef8e420-e6a2-49f5-b612-c0b2dced0920
at web browser it returns a JSONObject as I wanted.
from the Android Log :
10-03 18:03:41.683: WARN/HTTP1:(4023): Method Not Allowed
10-03 18:03:41.683: WARN/HTTP3:(4023): java.io.IOException: Method Not Allowed
10-03 18:03:41.683: WARN/HTTP3:(4023): at requestHelper.doInBackground(requestHelper.java:84)
10-03 18:03:41.683: WARN/HTTP3:(4023): at requestHelper.doInBackground(requestHelper.java:1)
10-03 18:03:41.683: WARN/HTTP3:(4023): at android.os.AsyncTask$2.call(AsyncTask.java:185)
10-03 18:03:41.683: WARN/HTTP3:(4023): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
10-03 18:03:41.683: WARN/HTTP3:(4023): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
10-03 18:03:41.683: WARN/HTTP3:(4023): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
10-03 18:03:41.683: WARN/HTTP3:(4023): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
10-03 18:03:41.683: WARN/HTTP3:(4023): at java.lang.Thread.run(Thread.java:1096)

Categories

Resources