(1) I am using recyleview to fetch image, text & audio file from API. For text I used volley & for image use picasso, what I will use for audio file.
(2) after fetch the image & text when apply onclicklistener pass the info to another activity. Can pass only text not images.
What I need to do to solve this problem?
this is adapter part
viewHolder.textViewStory.setText(banglaItem.getStoryName());
viewHolder.textViewWritter.setText(banglaItem.getWritterName());
Picasso.get().load(banglaItem.getStoryImage()).fit().into(viewHolder.imageView);
viewHolder.linear.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(context,AudioActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("storyName",banglaItem.getStoryName());
intent.putExtra("storyImage",banglaItem.getStoryImage());
context.startActivity(intent);
}
});
this is the new activity part
public class AudioActivity extends AppCompatActivity {
TextView name;
ImageView image;
String nameStory;
String imageStory;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_audio);
name = findViewById(R.id.audioName);
image = findViewById(R.id.audioImage);
nameStory = getIntent().getStringExtra("storyName");
imageStory = getIntent().getStringExtra("storyImage");
name.setText(nameStory);
int resourceId = getResources().getIdentifier(imageStory,"drawable", getPackageName());
image.setImageResource(resourceId);
}
}
(1.) if you have complete url of your audio file then you can directly stream audio file using media player classes provided by android.
(2.) you are passing storyImage in next activity ,which is a url that you get from api. so you have to find same on next activity i.e
TextView name;
ImageView image;
String nameStory;
String imageStory;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_audio);
name = findViewById(R.id.audioName);
image = findViewById(R.id.audioImage);
nameStory = getIntent().getStringExtra("storyName");
imageStory = getIntent().getStringExtra("storyImage");
name.setText(nameStory);
Picasso.get().load(imageStory).fit().into(image);
//here image story contain url that you sent through first activity. As picasso uses cache, it will load (already loaded image in first activity) very smoothly from it cache.
}
Related
Originally in the project I have two image buttons, which I coded like the below:
XML:
<ImageView
android:layout_width="125dp"
android:layout_height="125dp"
android:id="#+id/sidebanner1"
android:padding="15dp"
/>
<ImageView
android:layout_width="125dp"
android:layout_height="125dp"
android:id="#+id/sidebanner2"
android:padding="15dp"
/>
Main_Activity.java
public class MainActivity extends Activity implements View.OnClickListener{
#Override
protected void onCreate(Bundle savedInstanceState) {
ImageView SideBanner1=(ImageView)findViewById(R.id.sidebanner1);
SideBanner1.setImageResource(R.drawable.sidebanner1);
SideBanner1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
String url1 = "http://www.chris.com";
Intent a = new Intent(Intent.ACTION_VIEW);
a.setData(Uri.parse(url1));
startActivity(a);
}
});
ImageView SideBanner2=(ImageView)findViewById(R.id.sidebanner2);
SideBanner2.setImageResource(R.drawable.sidebanner2);
SideBanner2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
String url2 = "http://www.peter.com";
Intent b = new Intent(Intent.ACTION_VIEW);
b.setData(Uri.parse(url2));
startActivity(b);
}
});
Now I have stored the images and url links in server, and created sql table in order to retrieve these information.
In the splash screen, I started to retrieve the information as follow:
JSONArray sidebannerAry = result.getJSONArray("sidebannerData");
for (int i = 0; i < sidebannerAry.length(); i++){
JSONObject temp = sidebannerAry.getJSONObject(i);
HashMap<String, String> map = new HashMap<String, String>();
String image = DefensiveClass.optString(temp, "bannerImage");
String url = DefensiveClass.optString(temp, "bannerURL");
map.put("image", image);
map.put("url", url);
MainActivity.sidebannerAry.add(map);
}
But now I got confused and not sure how to apply the data to the two buttons in MainActivity.
Can anyone guide me thru how to pass the image and link information retrieved to the two banner buttons so that they can use it. Thank you.
In MainActivity public class, I added:
public static ArrayList<HashMap<String,String>> sidebannerAry = new ArrayList<HashMap<String,String>>();
Problem solved, I was thinking assigning sidebannerAry to adapter to do it.
But I was stupid, all I need is just to load the image and have the onClickListener open up the website and load the url directly from the sidebannerAry.
As per your question you need to set your buttons with the information retrieved from api call, so you can simply store the values retrieved from api call(server) on local variables and apply those to the buttons as:
btnExample.setText(the_text_or_url_retrieved_from_server);
and if you want to set image to the button with the image url retrieved from server then you can use glide as:
Glide.with(context)
.load(url_retrieved_from_server)
.into(imageButton);
but make sure you use image button for this.
I am currently developing an app for playing PCM files and displaying their resulting line graph (thanks to jjoe64 for the GraphView).
My problem now is how to open a PCM file in a new activity. Basically, the app must display the line graph for the selected file. This certain file is a list entry, so, when the user clicks the filename from the list, it will be directed to a new activity within the app for graph display.
Here is the code for the opening of a file in a list, a.k.a. the first part of my problem (from DBActivity.java):
public final static String EXTRA_FILE = "com.example.ecg_to_go.FILENAME";
getListView().setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
final int sFilePosition = position;
sFile = files[sFilePosition];
Intent openFile = new Intent(DBActivity.this, ContentActivity.class);
Uri uri = Uri.fromFile(sFile);
openFile.putExtra(EXTRA_FILE, uri);
startActivity(openFile);
}
});
And here is the second part of my problem (from ContentActivity.java):
private File ecgFile;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_content);
ecgFile = new File(DBActivity.EXTRA_FILE);
playEcg(ecgFile); // display the PCM file
}
Look here for how to get the extras you gave to the intent, in the started activity. You just have to call getIntent().getExtras() which returns you a bundle and the documentation is here :http://developer.android.com/reference/android/os/Bundle.html
Good luck :)
I am trying to make a button in one activity (SetupMenu) that, when pressed, puts an int into the intent and carries that over to the next activity (IntroActivity) where a textView will retrieve the int and display it.
Problem is, when the app runs and I get to the activity and press the button, the app crashes and my emulator tells me that "Unfortunately [my app] has stopped working."
I feel like I've tested every possible angle to get this to work. I should note that the button has worked fine, the textview has worked fine, everything else is working smoothly - I only run into issues when I try retrieving the intent and displaying it in textView. I tried passing through a String instead of an Int and also had issues (my string would not appear). Any pointers?
SetupMenu activity (here I put an int into my intent):
public class SetupMenu extends Activity {
public final static String extra_progress_key = "com.example.angelsanddemons.track_players";
public int track_players = 0;
public void to_intro(View view) {
Intent intent = new Intent(this, IntroActivity.class);
intent.putExtra(extra_progress_key, track_players);
startActivity(intent);
}
IntroActivity activity (here I try to retrieve the int from the intent):
public class IntroActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
int temp = intent.getIntExtra(SetupMenu.extra_progress_key, 0 );
TextView textView = new TextView(this);
textView.setText(temp);
setContentView(textView);
}
}
One problem is that you can't set a TextView's text to an int; you'll need to first convert it to an string. It's also not a good idea to be manipulating views before you've inflated them, so perhaps your onCreate() should be:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
int temp = intent.getIntExtra(SetupMenu.extra_progress_key, 0 );
TextView textView = new TextView(this);
setContentView(textView);
textView.setText(String.valueof(temp));
}
I see nothing that ensure that SetupMenu activity is created and in memory when IntroActivity is launched. To make sure, don't pass the variable, but the string itself and check if it work:
int temp = intent.getIntExtra("com.example.angelsanddemons.track_players", 0 );
hi I am trying to load an image from an url using novoda Direct ImageLoader method
right now I have this class
public class MainActivity extends Activity {
public class DirectLoading extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView iv=(ImageView) findViewById(R.id.imageView1);
ImageView ivv=(ImageView) findViewById(R.id.imageView2);
Bitmap b=new DirectLoader()
.download("https://upload.wikimedia.org/wikipedia/commons/a/ad/SmallStellatedDodecahedron.jpg");
Bitmap pic=new DirectLoader()
.download("http://www.coetail.com/mamitakagi1129/wp-content/themes/twentyten/images/headers/cherryblossoms.jpg");
ivv.setImageBitmap(pic);
iv.setImageBitmap(b);
}
private void guiBuilder() {
}
}
}
I should get 2 images into the 2 imageViews, but I am getting a blank screen. There is a "Hello world" string in the layout that is not displayed so I guess I do get the images but they are not displayed graphically.
As it says in readme file https://github.com/novoda/ImageLoader/blob/develop/README.md you should handle threading when using DirectLoader.download(), for example, using AsyncTask.
I am developing playing video application and taking screenshot of running video and display a screenshot in next activity, i am playing video and taking screenshot and i am not able to display screenshot in next activity please check my code and give me changes.
BitmapDrawable bitmapDrawable = new BitmapDrawable(bm);
image = (ImageView) findViewById(R.id.ImageView01);
// image.setBackgroundDrawable(bitmapDrawable);
String bitmap = image.toString();
System.out.println("Image getting++++++ : " + bitmap);
Intent intent = new Intent(VideoDemo.this, ScreenshotView.class);
intent.putExtra("BitmapImage", bitmap);
startActivity(intent);
public class ScreenshotView extends Activity
{ private String filename;
private ImageButton back;
private ImageView screenshot;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.screenshot);
screenshot =(ImageView)findViewById(R.id.screen);
back = (ImageButton)findViewById(R.id.backbutton);
back.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
finish();
}
});
System.gc();
Intent i = getIntent();
Bitmap bitmap = (Bitmap) i.getParcelableExtra("BitmapImage");
screenshot.setImageBitmap(bitmap);
}
}
Here your "bitmap" object is a string.
And you are passing a string object to your next activity.
That is why, you are not able to set image in you ImageView screenshot.
Can you try the below code and lemme know whether you fixed it.
Sending Object
Here is the code to send the Object from one to other class. One Important thing to send the Object is the class should implement the Serializable class.
The below Red Colored text should be same.
//MainActivity.java
Intent i = new Intent(MainActivity.this,startActivity.class);
ObjectClassName object = new ObjectClassName();
i.putExtra("THIS", Object);
Receiving Object
// startActivity.java
Intent i = getIntent();
ObjectClassName obj = (ObjectClassName) getIntent().getSerializableExtra("THIS");//
TypeCasting needed