I've looked up some answers but am not sure why mine is failing exactly...
The code looks something like this
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
String json = EntityUtils.toString(httpEntity);
//Convert to JsonArray
JSONArray jsonArray = new JSONArray(json);
Log.i(DEBUG_TAG, Integer.toString(jsonArray.length()));
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
Log.i(DEBUG_TAG, jsonObject.getString(KEY_ID));
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(KEY_ID, jsonObject.getString(KEY_ID));
map.put(KEY_TITLE, jsonObject.getString(KEY_TITLE));
map.put(KEY_ARTIST, jsonObject.getString(KEY_ARTIST));
map.put(KEY_DURATION, jsonObject.getString(KEY_DURATION));
map.put(KEY_VOTECOUNT, jsonObject.getString(KEY_VOTECOUNT));
map.put(KEY_THUMB_URL, jsonObject.getString(KEY_THUMB_URL));
map.put(KEY_GENRE, jsonObject.getString(KEY_GENRE));
//Adding map to ArrayList
if (Integer.parseInt(jsonObject.getString(KEY_VOTECOUNT)) == -1){
//If VoteCount is -1 then add to header
headerList.add(map);
}else {
songsList.add(map);
}
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
When I run logcat on String json, it seems to show correct info which is kind of like this...
{
"userdata": [
{
"id": "8",
"title": "Baby One More Time",
"artist": "Britney Spears",
"duration": "03:24:00",
"votes": "0",
"thumb_url": "http://api.androidhive.info/music/images/dido.png",
"genre": null
},
{
"id": "2",
"title": "As Long As You Love Me",
"artist": "Justin Bieber",
"duration": "05:26:00",
"votes": "0",
"thumb_url": "http://api.androidhive.info/music/images/enrique.png",
"genre": "Rock"
}
]
}
and the logcat on
JSONArray jsonArray = new JSONArray(json);
tells me that jsonArray.length()
10-31 22:57:28.433: W/CustomizedListView(26945): error! Invalid index
0, size is 0
Please let me know
Thank you,
I would like to have a checkbox preference that takes the user to a new (sub)preference screen if the user presses on the actual text (and not on the checkbox to the right).
Just as the control under Settings - Wireless - Mobile Network Settings - Access Point Names.
I am modifying the source code here: http://thinkandroid.wordpress.com/2009/12/30/getting-response-body-of-httpresponse/
I get this error: non-static method getContentCharSet(org.apache.http.HttpEntity) cannot be referenced from a static context
String charset = getContentCharSet(entity);
This error is line 13 on the second box.
Any ideas? I have been really struggling with this code :-(
final Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("image/jpeg");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "[email protected]" });
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "this is the test");
emailIntent.putExtra(Intent.EXTRA_TEXT, "testing time");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(url));
Can anyone tell me how I can Dynamically add groups & children to an ExpandableListView. The purpose is to create a type of task list that I can add new items/groups to.
I can populate the view with pre-filled arrays but of course can't add to them to populate the list further. The other method i tried was using the SimpleExpandableListAdapter. Using this i am able to add groups from a List but when it comes to adding children i can only add 1 item per group.
public List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
public List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();
public void addGroup(String group) {
Map curGroupMap = new HashMap();
groupData.add(curGroupMap);
curGroupMap.put(NAME, group);
//Add an empty child or else the app will crash when group is expanded.
List<Map<String, String>> children = new ArrayList<Map<String, String>>();
Map<String, String> curChildMap = new HashMap<String, String>();
children.add(curChildMap);
curChildMap.put(NAME, "EMPTY");
childData.add(children);
updateAdapter();
}
public void addChild(String child) {
List children = new ArrayList();
Map curChildMap = new HashMap();
children.add(curChildMap);
curChildMap.put(NAME, child);
curChildMap.put(IS_EVEN, "This child is even");
childData.add(activeGroup, children);
updateAdapter();
}
My application takes userid from user as input, the userid is alphanumeric i.e just the first character is (a-z), other part is numeric. How can I validate input of this type ( like G34555) ?
I am very new to this, and I more looking for what information I need to study to be able to accomplish this.
What I want to do is use my GUI I have built for my app, but pull the information from a website.
If I have a website that looks like this:
(Sorry, can't post pics yet)
http://
dl.dropbox.com/u/7037695/ErrorCodeApp/FromWebsite.PNG
(full website can be seen at http://www.atmequipment.com/Error-Codes)
What would I need from the website so that if a user entered an error code here:
http://
dl.dropbox.com/u/7037695/ErrorCodeApp/InApp.PNG
It would use the search from the website, and populate the error description in my app?
I know this is a huge question, I'm just looking for what is actually needed to accomplish this, and then I can start researching from there. -- Or is it even possible?
I would like to show a notification that displays the progress of an
ongoing operation. That works well for me.
But at the same time the remote view should contain cancel button to stop the ongoing operation. The usual content intent should still do something else, i.e. not cancel the ongoing operation. It seems though that I can only have one intent.
I have to specify a contentIntent that is launched when clicking on
the notification: If I don't specify that I get something along those
lines:
E/ActivityManager( 62): Activity Manager Crash
E/ActivityManager( 62): java.lang.IllegalArgumentException: contentIntent required ...
For the "cancel" button I set another intent:
Intent cancelSyncIntent = new Intent("com.xyz.CANCEL_SYNC");
contentView.setOnClickPendingIntent(R.id.cancel_sync,
PendingIntent.getBroadcast(context, 0,
cancelSyncIntent, 0));
But this never works. I always get the content intent when the button
is clicked. It looks like I cannot use buttons in remote views of
notifications?!
I could probably display a text: "<< Press to cancel operation ", but that seems rather heavy handed.
I have a ProgressDialog that retrieves in background data from database by executing php script.
I'm using gson Google library. php script is working well when executed from browser:
{"surveys":[{"id_survey":"1","question_survey":"Are you happy with the actual government?","answer_yes":"50","answer_no":"20"}],"success":1}
However, ProgressDialog background treatment is not working well:
@Override
protected Void doInBackground(Void... params) {
String url = "http://192.168.1.4/tn_surveys/get_all_surveys.php";
HttpGet getRequest = new HttpGet(url);
Log.d("GETREQUEST",getRequest.toString());
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
Log.d("URL1",url);
HttpResponse getResponse = httpClient.execute(getRequest);
Log.d("GETRESPONSE",getResponse.toString());
final int statusCode = getResponse.getStatusLine().getStatusCode();
Log.d("STATUSCODE",Integer.toString(statusCode));
Log.d("HTTPSTATUSOK",Integer.toString(HttpStatus.SC_OK));
if (statusCode != HttpStatus.SC_OK) {
Log.w(getClass().getSimpleName(), "Error " + statusCode + " for URL " + url);
return null;
}
HttpEntity getResponseEntity = getResponse.getEntity();
Log.d("RESPONSEENTITY",getResponseEntity.toString());
InputStream httpResponseStream = getResponseEntity.getContent();
Log.d("HTTPRESPONSESTREAM",httpResponseStream.toString());
Reader inputStreamReader = new InputStreamReader(httpResponseStream);
Gson gson = new Gson();
this.response = gson.fromJson(inputStreamReader, Response.class);
}
catch (IOException e) {
getRequest.abort();
Log.w(getClass().getSimpleName(), "Error for URL " + url, e);
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
Log.d("HELLO","HELLO");
StringBuilder builder = new StringBuilder();
Log.d("STRINGBUILDER","STRINGBUILDER");
for (Survey survey : this.response.data) {
String x= survey.getQuestion_survey();
Log.d("QUESTION",x);
builder.append(String.format("<br>ID Survey: <b>%s</b><br> <br>Question: <b>%s</b><br> <br>Answer YES: <b>%s</b><br> <br>Answer NO: <b>%s</b><br><br><br>", survey.getId_survey(), survey.getQuestion_survey(),survey.getAnswer_yes(),survey.getAnswer_no()));
}
Log.d("OUT FOR","OUT");
capitalTextView.setText(Html.fromHtml(builder.toString()));
progressDialog.cancel();
}
HELLO Log is displayed.
STRINGBUILDER Log is displayed.
QUESTION Log is NOT displayed.
OUT FOR Log is displayed.
Survey Class:
public class Survey {
int id_survey;
String question_survey;
int answer_yes;
int answer_no;
public Survey() {
this.id_survey = 0;
this.question_survey = "";
this.answer_yes=0;
this.answer_no=0;
}
public int getId_survey() {
return id_survey;
}
public String getQuestion_survey() {
return question_survey;
}
public int getAnswer_yes() {
return answer_yes;
}
public int getAnswer_no() {
return answer_no;
}
}
Response Class:
public class Response {
ArrayList<Survey> data;
public Response() {
data = new ArrayList<Survey>();
}
}
Any help please concerning WHY the FOR loop is not executed.
Thank you for helping.
I am looking for an example of using a WebViewClient with shouldOverrideUrlLoading and using HttpPost.
I need to display a web page, keep it within my layout boundaries so it can not launch a new browser and also use HttpPost to send data to the host.
This logic is written in a function with signature
private void showDialog(final AdapterView<? extends Adapter> parent,
String title, String message, final Tag subject)
Is there a better way of doing this?
// refresh adapter
SimpleCursorAdapter adapter;
if (parent.getAdapter() instanceof WrapperListAdapter) {
adapter = (SimpleCursorAdapter) ((WrapperListAdapter) parent.getAdapter()).getWrappedAdapter();
} else {
adapter = (SimpleCursorAdapter) parent.getAdapter();
}
adapter.getCursor().requery();
adapter.notifyDataSetChanged();
Also, is there any point in having AdapterView<? extends Adapter> in the signature and not just AdapterView<?>?
Hello everybody!
I have a business need to create the NinePatchDrawable objects at runtime, this is, an exterior .png image is received from a server and it has to be applied in a button's background (for example) as a nine patch.
I have tried to create the NinePatchDrawable object, but the constructor asks me for a "byte[] chuck" that describes the patch. The thing is, I have no idea on how to build this chunck from a bitmap that does not have the 9patch information in it.
Any ideas on this topic? Am I seeing the problem from a wrong perpective?
Thanks!
For my AutoCompleteTextView I need to fetch the data from a webservice. As it can take a little time I do not want UI thread to be not responsive, so I need somehow to fetch the data in a separate thread. For example, while fetching data from SQLite DB, it is very easy done with CursorAdapter method - runQueryOnBackgroundThread. I was looking around to other adapters like ArrayAdapter, BaseAdapter, but could not find anything similar...
Is there an easy way how to achieve this? I cannot simply use ArrayAdapter directly, as the suggestions list is dynamic - I always fetch the suggestions list depending on user input, so it cannot be pre-fetched and cached for further use...
If someone could give some tips or examples on this topic - would be great!
I was following the progress dialog example in the ApiDemos.
all went great except for one thing - I want to remove the numbers that appear underneath the bar (those running numbers that run from 0 to .getMax().
couldn't find how to do it.
anyone?
Ori
dear friends,
i have created custom list view using
class EfficientAdapter extends BaseAdapter implements
{
private LayoutInflater mInflater;
private Context context;
public EfficientAdapter(Context context) {
mInflater = LayoutInflater.from(context);
this.context = context;
}
public View getView(final int position, View convertView,
ViewGroup parent) {
ViewHolder holder;
convertView = mInflater.inflate(R.layout.adaptor_content, null);
convertView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
and other necessary methods... also
}
using touch screen when i click on list item OnClickListener of list item is called.
but when i use Mouse Ball / Track Ball (Phone Hardware) to click on ListItem OnClickListener of list item is not called.
can any one guide me is this Phone bug or My Fault?
any help would be appriciated.
Hello,
Sorry, this's my first time to ask a question here. So, I don't have the permission to upload the image to describe. Never Mind. What I would like to make is a row of ListView like this. The block on the left is an icon.
Much appreciated if you could feedback the correct XML tags. Thanks.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-------
| | some text some text
| | some text some text
-------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I'm using a TableLayout for an Activity and if I have more than a certain number of TableRows a vertical line appears to the right of the screen.
If I use fewer Views in my layout, the line disappears. If this is not a bug, where should I look in my layout for problems?
Hi
I defined a remote service over a AIDL file. Now i want to access this service in a different application. But how can I do that? The AIDL file is not accessible in my second application, and if i just copy the AIDL file, then the service can^^t be found.
Any hints for that problem??
Thanks Sebi
Hi,
Can someone tell if why when starting an activity with startActivity(intent) , calling getParent() in onCreate() of the new created activity returns a nul ?
Also how could I obtain the parent of an activity created in such a way ? Can a reference of the activity below the current activity in the activity stack be obtained ?
While i'm clicking a button in my menu list (for example select all)my application is getting force closed.Why is it so???in eclipse emulator it is working fine,but in phone(i'm using LG620)it's getting force closed,as i've no cable with me,i can't debug it.
if i wanted to reference an int from another class how would i go about doing that???
public class Zoom extends View {
private Drawable image;
public int zoomControler=20;
public Zoom(Context context)
{
super(context);
image=context.getResources().getDrawable(R.drawable.icon);
setFocusable(true);
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
image.setBounds((getWidth()/2)-zoomControler, (getHeight()/2)-zoomControler, (getWidth()/2)+zoomControler, (getHeight()/2)+zoomControler);
image.draw(canvas);
}
}
class HelloOnTouchListener implements OnTouchListener{
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
return true;
}
}
in this case i want to reference the zoomControler from the first class in the second helloontouchlistener class
I am trying to swap the position of two buttons.
my swapping code looks as below.
private void exchangeButtons(Button btn1, Button btn2) {
// Create the animation set
AnimationSet exchangeAnimation = new AnimationSet(true);
TranslateAnimation translate = new TranslateAnimation( Animation.RELATIVE_TO_SELF, btn2.getLeft(),
Animation.RELATIVE_TO_SELF, btn1.getLeft(),
Animation.RELATIVE_TO_SELF, btn2.getRight(),
Animation.RELATIVE_TO_SELF, btn1.getRight()
);
translate.setDuration(500);
exchangeAnimation.addAnimation(translate);
// int fromX = btn1.getLeft();
// int fromY = btn1.getRight();
// int toX = btn2.getLeft();
// int toY = btn2.getRight();
Log.d("ArrangeMe", "view1 pos:" + btn1.getLeft() + ", " +btn1.getRight() + "view2 pos:" + btn2.getLeft() + ", " + btn2.getRight());
AnimationSet exchangeAnimation1 = new AnimationSet(true);
TranslateAnimation translate1 = new TranslateAnimation( Animation.RELATIVE_TO_SELF, btn1.getLeft(),
Animation.RELATIVE_TO_SELF, btn2.getLeft(),
Animation.RELATIVE_TO_SELF, btn1.getRight(),
Animation.RELATIVE_TO_SELF, btn2.getRight()
);
translate1.setDuration(500);
exchangeAnimation1.addAnimation(translate1);
// EXECUTE
btn1.startAnimation(exchangeAnimation);
btn2.startAnimation(exchangeAnimation1);
}
I call the code as below
exchangeButtons(button1, button2);
my layout looks as below
what happens when i execute the code is,
instead of the buttons exchanging their positions, they just disappear for sometime[may be 500 ms] and reappear as they were originally.
how to resolve this problem ? will it work properly in device ?
regards
Hey all,
I would like to make a Google map overlay with changable pins. An easy way to visualize this would be to think of a near real time overlay, where the pins are constantly changing location.
However, I can't seem to think of a safe way to do this with the ItemizedOverlay. The problem seems to be the call to populate - If size() is called by some maps thread, and then my data changes, then the result when the maps call accesses getItem() can be an IndexOutOfBoundsException.
Can anyone think of a better solution than overloading populate and wrapping super.populate in a synchronized block?
Perhaps I could get better luck using a normal Overlay? The Itemized one seems to exist to manage the data for you, perhaps I am making a fundamental mistake by using it?
Thanks for any help, my brain is hurting!
Hamy