|
Hi
I make one app have only one activity is main activity and it have
button
textview
linear layout
the json file i connect to it is
public static String URL_GET_Place = "https://api.foursquare.com/v2/venues/search?client_id=SVIBXYYXOEARXHDI4FWAHXGO5ZXOY204TCF1QJFXQLY5FPV4&client_secret=BAAJO1KXRWESGTJJGVON4W3WUFHAQDAJPLRIYJJ5OPHFQ5VI&v=20130815&ll=30.1136286,31.3280148&query=resturant";
what i need is get all items from this file item by item
based on three atributes and every click get next item
name,id,location
when i press the fab button to first time get first item
when i press the fab button to second time get second item
when i press the fab button to third time get third item
when i press the fab button to four time get four item
until i get all items in json file based on three attributs id,name,location
How i make that by code if possible help me
|
|
|
|
|
ahmed_sa wrote: How i make that by code if possible help me Exactly what do you need help with, processing the file, responding to button clicks, populating a listview? What code have you put together so far? What is it (not) doing?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
 My code is
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_eating);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
card1 = (LinearLayout) findViewById(R.id.card_one);
card2 = (LinearLayout) findViewById(R.id.card_two);
card3 = (LinearLayout) findViewById(R.id.card_three);
tvTitle1 = (TextView) findViewById(R.id.tv_title1);
tvTitle2 = (TextView) findViewById(R.id.tv_title2);
tvTitle3 = (TextView) findViewById(R.id.tv_title3);
tvDetails1 = (TextView) findViewById(R.id.tv_details1);
tvDetails2 = (TextView) findViewById(R.id.tv_details2);
tvDetails3 = (TextView) findViewById(R.id.tv_details3);
card1.setonclickListener(this);
card2.setonclickListener(this);
card3.setonclickListener(this);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setonclickListener(new View.onclickListener() {
@Override
public void onclick(View view) {
if (count < 3) {
new GetPlace().execute();
}
}
});
}
class GetPlace extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(EatingActivity.this);
pDialog.setMessage("Picking an Item...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
}
protected Void doInBackground(Void... args) {
try {
List<NameValuePair> dataList = new ArrayList<NameValuePair>();
JSONObject json = jsonParser.
makeHttpRequest(AppConfig.URL_GET_Place, "GET", dataList);
JSONObject meta = json.getJSONObject("meta");
success = meta.getInt("code");
JSONObject response = json.getJSONObject("response");
JSONArray venues = response.getJSONArray("venues");
for (int i = 0; i < venues.length(); i++) {
selectedPlace = new Place();
JSONObject object = venues.getJSONObject(i);
selectedPlace.setTitle(object.getString("name"));
selectedPlace.setId(object.getString("id"));
JSONObject location = object.getJSONObject("location");
JSONArray formattedAddress=location.getJSONArray("formattedAddress");
Log.d("length",formattedAddress.length()+"");
String currentLocation="";
for (int j=0;j<formattedAddress.length();j++)
{
currentLocation+=formattedAddress.getString(j)+", ";
Log.d("address",currentLocation);
}
selectedPlace.setAddress(currentLocation);
selectedPlace.setLat(location.getDouble("lat"));
selectedPlace.setLng(location.getDouble("lng"));
Log.d("name", selectedPlace.getTitle());
places.add(selectedPlace);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(Void args) {
if (!pDialog.isShowing()) {
pDialog.dismiss();
if (success == 200) {
if (count == 0) {
card1.setVisibility(View.VISIBLE);
tvTitle1.setText(places.get(count).getTitle());
tvDetails1.setText(places.get(count).getAddress());
} else if (count == 1) {
card2.setVisibility(View.VISIBLE);
tvTitle2.setText(places.get(count).getTitle());
tvDetails2.setText(places.get(count).getAddress());
} else if (count == 2) {
card3.setVisibility(View.VISIBLE);
tvTitle3.setText(places.get(count).getTitle());
tvDetails3.setText(places.get(count).getAddress());
}
count++;
} else {
Toast.makeText(EatingActivity.this, "Couldn't find any nearby places", Toast.LENGTH_LONG).show();
}
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home)
finish();
return super.onOptionsItemSelected(item);
}
@Override
public void onclick(View view) {
int index = 0;
if (view.getId() == card1.getId()) {
index = 0;
} else if (view.getId() == card2.getId()) {
index = 1;
} else if (view.getId() == card3.getId()) {
index = 2;
}
String strUri = "http://maps.google.com/maps?q=loc:"
+ places.get(index).getLat() + "," + places.get(index).getLng() +
"(" + places.get(index).getTitle() + ")";
Log.d("url",strUri);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(strUri));
startActivity(intent);
}
}
|
|
|
|
|
What i need is when click fab button
on first time show first item
on second time click show second item
until it get all items in json file
meaning i need to customize code above
to show all items not three items but based on fab click
every click show item
|
|
|
|
|
That sounds like the wrong way to do it. Why not use a scrollable view (ListView or similar), populate it with all the items in the json data, and let the user scroll through it as necessary.
|
|
|
|
|
Thank you for reply
OK i will try with list view but
i need when click fab button retrieve me item by item
like scenario i will show
I will click fab button to first time it give me first item
when click fab to second time it give me second item
not show all item when press button
what i need actually press button get me item
when i press again give me next item until i get all items from json file
|
|
|
|
|
I'm not sure why you would want to do that, but I do not suppose it is too difficult. Just make sure that your reference to the JSON data is a class variable so you can access it from any method. You then just need to read the next record every time the button is pressed. Alternatively you could read all the data into some sort of List and use an index value to read each record in turn, and reset the index when you reach the last record.
|
|
|
|
|
I agree.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
ahmed_sa wrote: if (!pDialog.isShowing()) {
pDialog.dismiss(); This seems backward. Why would you dismiss a dialog that is not showing?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Thank you for reply
i will post my code full in another thread
and what i need to do
|
|
|
|
|
Hello all,
I have two layouts, one is below the other one. When user swipes down, I want upper layout to be bigger, and lower layout to be smaller and vice versa for when user swipes up. How can I achieve that?
Here is my layout :
="1.0"="utf-8"
<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="com.example.mydomain.myapplication1212.MainActivity">
<LinearLayout
android:id="@+id/above_element"
android:layout_width="match_parent"
android:layout_height="250dp"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/summ"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_below="@+id/above_element"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/flowers"/>
</LinearLayout>
</RelativeLayout>
|
|
|
|
|
|
Thank you for your answer, but your example doesn't answer my problem.
|
|
|
|
|
I'm sorry but you have not really given enough detail of what your problem is.
|
|
|
|
|
I have shared the problem and the source code. Can you tell me what I'm missing? Thanks.
|
|
|
|
|
What do you need help with, responding to the swipe gesture, or resizing the layout?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Hi.. I am new to Xamarin Forms. I am building an application in using PCL. I have an external trigger event like trigger gun event. I am unable to find the triggered event. Please help me .
my sample code like below and it works in android but I am expecting PCL Xamarin Form
public override Boolean OnKeyDown(Keycode keyCode, KeyEvent e)
{
}
|
|
|
|
|
Any problem for my coding? Please help, thanks.
xml code
="1.0"="utf-8"
<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="com.example.user.myapplication.MyActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"
android:layout_gravity="center_horizontal"
android:id="@+id/btnsubmit"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="100dp"
android:layout_height="45dp"
android:text="key in here"
android:id="@+id/medittext" />
</RelativeLayout>
MyActivity.java
package com.example.user.myapplication;
import android.app.Activity ;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import static com.example.user.myapplication.R.*;
public class MyActivity extends Activity implements View.OnClickListener {
EditText mtext;
Button mbutton;
<a href="http://www.codeproject.com/Members/OverRide">@Override</a>
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(layout.activity_my);
mtext = (EditText)findViewById(id.medittext);
mbutton = (Button)findViewById(id.btnsubmit);
mbutton.setOnClickListener(this);
}
<a href="http://www.codeproject.com/Members/OverRide">@Override</a>
public void onClick(View v) {
Intent intent = new Intent(this, ViewActivity.class);
String message = mtext.getText().toString();
intent.putExtra("mtext",message);
startActivity(intent);
}
}
ViewActivity.java
package com.example.user.myapplication;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class ViewActivity extends Activity{
TextView tview;
<a href="http://www.codeproject.com/Members/OverRide">@Override</a>
protected void onCreate(Bundle saveInstancestate) {
super.onCreate(saveInstancestate);
setContentView(R.layout.view);
tview = (TextView)findViewById(R.id.tvView);
Intent intent = getIntent();
String abc = intent.getStringExtra("abc");
tview.setText(abc);
}
}
modified 31-May-16 11:13am.
|
|
|
|
|
Can you just move your head slightly to the left? You're in the way of the hidden camera we've installed behind you, and we can't see the error details on your screen.
Oh, wait; we don't have a camera pointing at your screen. We also don't have remote access to your computer, nor telepathy.
If you don't tell us what the error is, how do you think anyone will be able to fix it?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
No error checking, no try /catch clauses, and the name of the extra differs between the put (mtext) and the get (abc). How exactly are we supposed to help you?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
I'm new to Android programming and I'm not really sure what to search for to get an answer on this.
I'm writing an app that controls a 600W jukebox i made 15 years ago. I wrote the player code for wimdows and I want to be able to go into apps like YouTube, share the link to my app, send it to my Jukebox via TCP, and display it on the screen.
The only piece I'm missing is how do you get your app on the share to list? The list that comes up when you click a share button in say..... YouTube. How is it managed after your app is chosen? Can you pick and choose what apps can share to your app? Thanks!
|
|
|
|
|
Mike8855 wrote:
The only piece I'm missing is how do you get your app on the share to list? Modify your app's AndroidManifest.xml file. Check out the android:mimeType category. For example, I have an app that handles .txt files. For that activity in the AndroidManifest.xml file, I have this:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter> Now anytime a text file is selected, either through some sort of file manager (e.g., Astro), or opened as an email attachment, my app shows up in the list of apps that can handle that file type.
Mike8855 wrote: Can you pick and choose what apps can share to your app? Thanks! No, you let the Android framework know what file types your app can handle (e.g., text files, jpeg images, URLs).
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
modified 24-Apr-16 22:16pm.
|
|
|
|
|
|
 Next major roadblock....
I created a class within MainActivity to handle the intent. It just crashes when clicking the app on the share list. All this has to do is populate a string variable and MainActivity will see it in a background task.
The error:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.remoteapp.manderson.jboxcontroller/com.remoteapp.manderson.jboxcontroller.MainActivity$NextActivity}: java.lang.InstantiationException: java.lang.Class<com.remoteapp.manderson.jboxcontroller.MainActivity$NextActivity> has no zero argument constructor
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.InstantiationException: java.lang.Class<com.remoteapp.manderson.jboxcontroller.MainActivity$NextActivity> has no zero argument constructor
Manifest:
<activity
android:name=".SplashActivity"
android:label="@string/app_name"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity">
</activity>
<activity android:name=".MainActivity$NextActivity" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.SEND" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
MainActivity class heading:
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
Sub class:
public class NextActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent receivedIntent = getIntent();
String receivedText = receivedIntent.getStringExtra(Intent.EXTRA_TEXT);
if (receivedText != null){
MainActivity.this.playURL =receivedText;
}
}
In my first try in a separate activity:
public class ActivityFromExt extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent receivedIntent = getIntent();
String receivedText = receivedIntent.getStringExtra(Intent.EXTRA_TEXT);
if (receivedText != null) {
Intent i = new Intent(getApplicationContext(), MainActivity.NextActivity.class);
i.putExtra("URL", receivedText);
startActivity(i);
}
}
}
This would crash at startActivity.
Thanks
|
|
|
|
|
Mike8855 wrote:
This would crash at startActivity. Try surrounding the relevant parts of the code with a try/catch block. You should also consider stepping through the code using the debugger.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|