arjun narahari

Greenhorn
+ Follow
since Oct 24, 2014
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by arjun narahari

i have written a program in which i am displaying a gridview of images and when i click on the image another activity opens which has a viewpager to slide my images and there is also a horizontal scrollview at the bottom of the same page which has the same images which is seen in my gridview , till here everything works fine , and yea all the images are being read from my sdcard Now when i click on the images inside my horizontal scrollview , the image which is displayed up in my viewpager should change , example , like the gallery of s4 , so i am not getting how to do it

My Code :Inside my imageview.onclick i do not know what to do for my program to work , please provide suggestions according to my program ,please need some help

public class FullScreenViewActivity extends Activity {

private Utils utils;
private FullScreenImageAdapter adapter;
private ViewPager viewPager;
LinearLayout myGallery;
ImageView iView;
int i;
String path;
int id;
File[] files;
HorizontalScrollView scrollView;
int position;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fullscreen_view);

viewPager = (ViewPager) findViewById(R.id.pager);
myGallery = (LinearLayout) findViewById(R.id.mygallery);
scrollView = (HorizontalScrollView) findViewById(R.id.horizontal1);
scrollView.setBackground(getResources().getDrawable(R.drawable.border));
String ExternalStorageDirectoryPath = Environment
.getExternalStorageDirectory().getAbsolutePath();

String targetPath = ExternalStorageDirectoryPath + "/Pictures/raw";
Toast.makeText(getApplicationContext(), targetPath, Toast.LENGTH_LONG)
.show();
File targetDirector = new File(targetPath);

files = targetDirector.listFiles();

for (File file : files) {

myGallery.addView(insertPhoto(file.getAbsolutePath()));

}

utils = new Utils(getApplicationContext());

Intent i = getIntent();
position = i.getIntExtra("position", 0);

adapter = new FullScreenImageAdapter(FullScreenViewActivity.this,
utils.getFilePaths());

viewPager.setAdapter(adapter);

// displaying selected image first
viewPager.setCurrentItem(position);
}

private View insertPhoto(final String path) {

final Bitmap bm = decodeSampledBitmapFromUri(path, 220, 220);

LinearLayout layout = new LinearLayout(getApplicationContext());
layout.setLayoutParams(new LayoutParams(250, 250));
layout.setGravity(Gravity.CENTER);

ImageView imageView = new ImageView(getApplicationContext());
imageView.setLayoutParams(new LayoutParams(220, 220));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setImageBitmap(bm);

// imageView.setId(i);
// iView.setId(i);
// viewPager.setId(i);

imageView.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
int id = v.getId();
viewPager.setCurrentItem(id);

}

});

layout.addView(imageView);

return layout;
}

public Bitmap decodeSampledBitmapFromUri(String path, int reqWidth,
int reqHeight) {

Bitmap bm = null;

// First decode with inJustDecodeBounds=true to check dimensions final
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, options);

// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth,
reqHeight);

// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
bm = BitmapFactory.decodeFile(path, options);

return bm;
}
}
9 years ago
i wrote a program in which my images are read from sdcard and shown in as a gridview and when clicked on any image on the gridview , bigger image opens in another activity , i have also added a share button to share my image to different applications example whatsapp , so when i click on share , a chooser popsup and i also reach safely inside whatsapp where i select a user but when i select a user my image is not shown , below is the picture of the screen after i select a user

My code for the above

public class FullScreenImageAdapter extends PagerAdapter {

private Activity _activity;
private ArrayList<String> _imagePaths;
private LayoutInflater inflater;
Intent intent, chooser;

// constructor
public FullScreenImageAdapter(Activity activity,
ArrayList<String> imagePaths) {
this._activity = activity;
this._imagePaths = imagePaths;
}

@Override
public int getCount() {
return this._imagePaths.size();
}

@Override
public boolean isViewFromObject(View view, Object object) {
return view == ((RelativeLayout) object);
}

@Override
public Object instantiateItem(final ViewGroup container, int position) {
TouchImageView imgDisplay;
final Button btnClose, btnShare;

inflater = (LayoutInflater) _activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View viewLayout = inflater.inflate(R.layout.layout_fullscreen_imag,
container, false);

imgDisplay = (TouchImageView) viewLayout.findViewById(R.id.imgDisplay);
btnClose = (Button) viewLayout.findViewById(R.id.btnClose);
btnShare = (Button) viewLayout.findViewById(R.id.btnShare);

BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bitmap = BitmapFactory.decodeFile(_imagePaths.get(position),
options);
imgDisplay.setImageBitmap(bitmap);


btnShare.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
intent = new Intent(Intent.ACTION_SEND);
Uri imageuri = Uri.parse("file://sdcard//Pictures//raw "
+ _imagePaths);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_STREAM, imageuri);
chooser = Intent.createChooser(intent, "Share image via....");
container.getContext().startActivity(chooser);

}
});

((ViewPager) container).addView(viewLayout);

return viewLayout;
}
i need to know where i am going wrong and please give suggestions thanking you
9 years ago
i need to change my text in the header when i click on the textview , i made my best effort to do somethings, but i m not getting the result
i will post the code and if anyone can help me out and tell me where i m going wrong , it will be of great help

this is my results.xml where my listview and the header with textview(the one which is to be set inside the java code) is there ,


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/White" >

<RelativeLayout
android:id="@+id/rltHeader"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#27acc3" >

<ImageView
android:id="@+id/imgBackReuslt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:onClick="onClick"
android:src="@drawable/arrow" />

<TextView
android:id="@+id/txtHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textColor="@color/White"
android:textSize="20dp"
android:textStyle="bold" />
</RelativeLayout>

<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/rltHeader"
android:layout_marginRight="5dp"
android:divider="@color/LightGray"
android:dividerHeight="4px" >
</ListView>

</RelativeLayout>

this is my another xml where i have displayed how the listviews every Row will appear

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >



<RelativeLayout
android:layout_width="match_parent"
android:layout_height="100dp">

<RelativeLayout
android:id="@+id/rltRow"
android:layout_width="17dp"
android:layout_height="100dp"
android:layout_alignParentTop="true"
android:background="@drawable/r_list" >
</RelativeLayout>

<ImageView
android:id="@+id/imageView1"
android:layout_width="83dp"
android:layout_height="80dp"
android:layout_alignBottom="@+id/rltRow"
android:layout_alignParentRight="true" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/imageView1"
android:layout_marginLeft="16dp"
android:layout_marginTop="22dp"
android:layout_toRightOf="@+id/rltRow"
android:text="TextView"
android:textColor="@color/Black"
android:textSize="14dp" />

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView2"
android:layout_alignLeft="@+id/textView2"
android:text="TextView"
android:textColor="@color/Black" />

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/rltRow"
android:layout_alignLeft="@+id/textView2"
android:text="TextView"
android:textColor="@color/Black" />

<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_alignTop="@+id/imageView1"
android:text="TextView"
android:textColor="@color/Black"
android:textSize="12dp" />

<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/textView2"
android:text="TextView"
android:textColor="@color/Black"
android:textSize="12dp" />
</RelativeLayout>

</RelativeLayout>

Now the Java part
This is the List_Activity class where i have displayed all the textviews , there are 6 textviews which when clicked , an activity will appear Results.java , for all the textviews when clicked the same activity Results.java is opened

package com.demo.Test;

import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class Family_List_Activity extends Activity {
ImageView iv;
TextView t1, t2, t3, t4, t5, t6, headervalue;
String header_result = "";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_info);
iv = (ImageView) findViewById(R.id.imgBackReuslt);
t1 = (TextView) findViewById(R.id.text1);
t2 = (TextView) findViewById(R.id.text2);
t3 = (TextView) findViewById(R.id.text3);
t4 = (TextView) findViewById(R.id.text4);
t5 = (TextView) findViewById(R.id.text5);
t6 = (TextView) findViewById(R.id.text6);

t1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("com.demo.Test.RESULTS");
intent.putExtra("Results for Self", header_result);
startActivity(intent);
}
});
t2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("com.demo.Test.RESULTS");
intent.putExtra("Results for Mary(Wife)", header_result);
startActivity(intent);
}
});
t3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// name = t3.getText().toString();
Intent intent = new Intent("com.demo.Test.RESULTS");
intent.putExtra("Results for Alex(Child-1)", header_result);
startActivity(intent);
}
});
t4.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("com.demo.Test.RESULTS");
intent.putExtra("Results for Steven(Child-2)", header_result);
startActivity(intent);
}
});
t5.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("com.demo.Test.RESULTS");
intent.putExtra("Results for Robert(Father)", header_result);
startActivity(intent);
}
});
t6.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("com.demo.Test.RESULTS");
intent.putExtra("Results for Diana(Mother)", header_result);
startActivity(intent);
}
});

}

public void onClick(View v) {
super.onBackPressed();
finish();
}
}

Now the main class Results.java , the activity which opens when clicked on the textviews described the previous class

package com.demo.Test;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class Results extends Activity {
TextView header;
ImageView iv;
ListView lv;
String title;

int[] images = { R.drawable.photo_bg, R.drawable.photo_bg,
R.drawable.photo_bg, R.drawable.photo_bg, R.drawable.photo_bg,
R.drawable.b_list, R.drawable.g_list, R.drawable.r_list,
R.drawable.v_list };

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.results);
iv = (ImageView) findViewById(R.id.imgBackReuslt);
header = (TextView) findViewById(R.id.txtHeader);

lv = (ListView) findViewById(R.id.listView1);
Bundle extras = getIntent().getExtras();
if (extras != null) {
title = extras.getString("header_result");
}
ResultsAdapter adapter = new ResultsAdapter(getBaseContext(), doc,
diag, dt, images, docname, diagname);
lv.setAdapter(adapter);
}

so what changes i have to make so that the header text gets changed when i click on the textviews in the List_Activity accordingly
any suggestions are welcomed

9 years ago
hello everyone , i am new to this forum and also to android
i am here to seek knowledge from everyone out there

i have a question regarding listview
i wanted to know about how to create a listview ,say a simple list of 5 items, just displaying them when clicked on a button ? can anyone please tell me how to do it with onClick ??
any suggestions are welcomed
thanking you
9 years ago