I've been able to pass a selected image from grid view to a new full screen activity. I am now trying to capture the EXIF data from the image and pass it into a new activity.
The first activity of passing the int from grid view seems to be working fine.
public class test extends Activity {
public static int pos;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.thumb);
GridView gridview = (GridView) findViewById(R.id.thumbgridview);
gridview.setAdapter(new tImageAdapter(this));
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Intent intent = new Intent(test.this,test2.class);
pos=position;
intent.putExtra("pos", pos);
startActivity(intent);
finish();
}
});}
}
The second activity which displays the full image seems to be working fine.
public class test2 extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.full);
Bundle bundle= getIntent().getExtras();
ImageView image = (ImageView) findViewById(R.id.imagefull);
int pos = bundle.getInt("pos");
bundle.getFloat(ExifInterface.TAG_MAKE);
tImageAdapter obj = new tImageAdapter(this);
image.setImageResource(obj.tThumbIds[pos]);
Button bDIR = (Button) findViewById(R.id.bDIR);
bDIR.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(test2.this,Direct.class);
intent.putExtra(ExifInterface.TAG_MAKE, 0);
startActivity(intent);
finish();
}
});
Now when I proceed to the final activity all I am seeing in the text view is the word Make.
public class Direct extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.newthumb);
Bundle bundle= getIntent().getExtras();
bundle.getFloat(ExifInterface.TAG_MAKE);
TextView textview = (TextView) findViewById(R.id.dirtext);
textview.setText(ExifInterface.TAG_MAKE);
}
}
I am not getting any errors in debug and there hasn't been a single force close issue. Is there something I am missing? I've only been working with java for a couple weeks but this type of activity seems like it should be doable. (or I'm just an idiot)
Thanks!
bundle.getFloat(ExifInterface.TAG_MAKE); does not read anything. You are nowhere actually reading the Exif data from the image file. You simply are showing in the TextView the content of the static String named ExifInterface.TAG_MAKE.
The documentation is available: ExifInterface. You will need to do something like:
ExifInterface exifReader = new ExifInterface(filename);
textview.setText(exifReader.getAttribute(ExifInterface.TAG_MAKE));
Related
I want to display image from internet from main activity to another activity. But it is not working. What I have done:
// Main Activity
gameListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
// Find the current game that was clicked on
Games currentGame = mAdapter.getItem(position);
// Convert the String URL into a URI object (to pass into the Intent constructor)
Uri gameUri = Uri.parse(currentGame.getUrl());
// Create a new intent to view the game URI
Intent i = new Intent(GamesActivity.this,PreviewActivity.class);
i.putExtra("value",gameUri);
startActivity(i);
}
});
// Second Activity
public class PreviewActivity extends AppCompatActivity {
ImageView img;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_preview);
img = findViewById(R.id.imagePreview);
Uri i = getIntent().getData();
Picasso.with(this).load(i).into(img);
}
}
Intent intent=getIntent();
String i=intent.getStringExtra("value");
Picasso.with(this).load(i).into(img);
And url in string form.
I am trying to perform the makeSceneTransitionAnimation in my code but it doesn' t seem to work (it tells me that the method cannot be resolved). here is my code:
public class MainActivity extends Activity {
GridView gridview_id;
RelativeLayout second_activity_layout;
public int[] image_id = {R.drawable.banana, R.drawable.kiwi, R.drawable.oatmeal, R.drawable.coconut};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gridview_id = (GridView) findViewById(R.id.gridview_id);
second_activity_layout = (RelativeLayout) findViewById(R.id.second_activity_layout);
gridview_id.setAdapter(new objectAdapter(this));
gridview_id.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id){
Intent intent = new Intent (view.getContext(), SecondActivity.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
ActivityOptionsCompat options = ActivityOptions.makeSceneTransitionAnimation(MainActivity.this,(image_id[position]) , getString(R.string.banana_transition));
startActivity(intent, options.toBundle());
}
else{
startActivity(intent);
}
}
});
}
}
to make things a little more clear: I have a GridView in my MainActivity that contains clickable images, when an image is pressed, I want that particular image to display in my SecondActivity.
Please let me know if you have the solution to this, it would really help me out.
-Vidal
You could use the "compat" variant of this method:
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(MainActivity.this,(image_id[position]) , getString(R.string.banana_transition));
ActivityCompat.startActivity(MainActivity.this, intent, options.toBundle());
i have many buttons in main activity that each button link to another activity that contain listview that each item in listview link one html file that is in asset folder.
in my codes i'm using one webview activity for each activity.
how can i use one same webview activity for all activity.
i have eight different activities with different html files.
and i try to use one webview for others and always result is one html for all address.
one of my activities:
public class Dia_Page extends ListActivity {
public ListView lv;
public String number_of_keys;
public String[] values = new String[] {"dia 1",
"dia 2","dia 3"};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dia__page);
setListAdapter(new MyAdapter(this,android.R.layout.simple_list_item_1,R.id.textView1,values));
lv = getListView();
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, final View view,
int position, long id) {
Intent myIntent = new Intent(Dia_Page.this,Dia_sec.class);
myIntent.putExtra("key",position);
startActivity(myIntent);
}
});
}
my webview activity:
web2.setWebViewClient(new myWebClient());
web2.getSettings().setJavaScriptEnabled(true);
int pos = getIntent().getIntExtra("key", 0);
if (pos == 0) {
web2.loadUrl("file:///android_asset/dia/diaone.html");
} else if (pos == 1) {
web2.loadUrl("file:///android_asset/dia/diatwo.html");
} else if (pos == 2) {
web2.loadUrl("file:///android_asset/dia/diathree.html");
}
how can i use same webview for show all activities html that are in different activities.
I'm posting this answer to my question to those friends that have a problem like mine.
in each activity that contains listview i put this codes:
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, final View view,
int position, long id) {
Intent intent = new Intent(getApplicationContext(), Dia_sec.class);
switch(position){
case 0 :
intent.setData(Uri.parse("file:///android_asset/can/canone.html"));
break;
case 1 :
intent.setData(Uri.parse("file:///android_asset/can/cantwo.html"));
break;
case 2 :
intent.setData(Uri.parse("file:///android_asset/can/canthree.html"));
break;
// etc
}
startActivity(intent);
and in my webview "dia_sec" i add this code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dia_sec);
web2.loadUrl(getIntent().getDataString());
I had about 8 different activities that contains their own listview with different html files.
and now i put code in activity and link them to my webview page.
problem solved and now i have one webview that i use it to show all html files from different source and different listviews.
Thanks alot every body to try help me in this way
Try changing the code in webview activity like this.
`
String pos="";
in = getIntent();
web2.setWebViewClient(new myWebClient());
web2.getSettings().setJavaScriptEnabled(true);
pos= in.getStringExtra("key");
if (pos.equals("0")) {
web2.loadUrl("file:///android_asset/dia/diaone.html");
} else if (pos.equals("1")) {
web2.loadUrl("file:///android_asset/dia/diatwo.html");
} else if (pos.equals("2")) {
web2.loadUrl("file:///android_asset/dia/diathree.html");
}`
The code below give generate the ListView
public class MyList extends ListActivity {
static final String[] COUNTRIES = new String[] {LONG LIST OF COUNTRIES};
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(this,R.layout.main,COUNTRIES));
ListView lv=getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent,View view,int position,long id){
Intent i=new Intent(MyList.this,Another.class);
Bundle b = new Bundle();
b.putInt("id", (int)id);
intent.putExtras(b);
startActivity(intent);
}
});
}
}
Another activity is
public class Another extends Activity{
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.mainseocnd);
Bundle b=new Bundle();
int value= b.getInt("id",0);
TextView tv=(TextView)findViewById(R.id.text);
tv.setText(""+value);
}
}
Now when i click on the any list item say id-5 it always display 0
I want to get the listview item id like if user click second item in list the another acivity should display 1(b/c start with 0).
please correct me where it is going wrong.
Thanks in advance!!
In second activity instead of
Bundle b=new Bundle();
int value= b.getInt("id",0);
use
int value = icicle.getInt("id",0);
This will give you a solution... :)
Your way of retrieving the value is wrong:
Bundle b=new Bundle();
int value= b.getInt("id",0);
You create a new bundle and try to get a value from it, when there is none (it's new).
You have to get the extras supplied with the launch intent for that activity instead. Try
int value = getIntent().getIntExtra("id", 0);
instead.
i am new to Android and i am facing a problem in calling different activities from the same screen with same user interface.
Actually i want to implement d functionality of a tab activity but instead of tabs i am providing buttons and the buttons should act like tabs.
I am unable to do that. I am going wrong some where.
Can anyone help me please.....
HomeScreen class is:
public class HomeScreen extends Activity implements OnItemClickListener {
public Integer[] images = { R.raw.mobile, R.raw.note_books, R.raw.ac,
R.raw.drivers, R.raw.camera, R.raw.home_theaters, R.raw.pda,
R.raw.tv, R.raw.washing_machines, R.raw.scanners };
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.grid);
GridView gv = (GridView) findViewById(R.id.gridV);
LayoutInflater inflater = getLayoutInflater();
gv.setAdapter(new GridViewAdapter(images, inflater));
gv.setOnItemClickListener(this);
if (StaticUtils.scheckStatus){
parseData();
}
}
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Intent contents = new Intent(HomeScreen.this, Cat.class);
contents.putExtra("homescreen", arg2);
startActivity(contents);
}
Cat.class is this:
class Cat extends Activity implements OnClickListener{
private Button mBtnContents, mBtnBrand, mBtnCategory, mBtnBack;
#Override
public void onCreate(Bundle si){
super.onCreate(si);
setContentView(R.layout.gridtab);
int i = getIntent().getIntExtra("homescreen", 0);
mBtnContents=(Button) findViewById(R.id.btnContents);
mBtnContents.setOnClickListener(this);
mBtnBrand=(Button) findViewById(R.id.btnBrand);
mBtnBrand.setOnClickListener(this);
mBtnCategory=(Button) findViewById(R.id.btnCategory);
mBtnCategory.setOnClickListener(this);
mBtnBack=(Button) findViewById(R.id.btnBack);
mBtnBack.setOnClickListener(this);
}
#Override
public void onClick(View v) {
if(v==mBtnContents){
int i = getIntent().getIntExtra("homescreen", 0);
Intent in=new Intent(Cat.this, Pc.class);
in.putExtra("homescreen", i);
startActivity(in);
} else if(v==mBtnBrand){
startActivity(new Intent(Cat.this, Sd.class));
} else if(v==mBtnCategory){
startActivity(new Intent(Cat.this, Sbc.class));
} else if(v==mBtnBack){
startActivity(new Intent(Cat.this, Hs.class));
}
}
}
When i click on contents button its displaying the details but when i click on the other buttons its not showing anythng
Instead of "v==mBtnContents" use "v.equals(mBtnContents)" because View is an object.