ListView is not showing, any assistance is greatly appreciated! I am able to display products with ListView alone but I cannot figure out how to display it below my Relative Layout.
Cart.java:
public class Cart extends AppCompatActivity {
private String user;
static CartChangeListener cartChangeListener;
ProductsAdapter adaptCart;
ArrayList<Product> cartItems = new ArrayList<>();
Menu menu;
float total = (float)0.00;
float shipCost = 15;
float tax = (float)0.07;
String URI;
TextView subTotal;
TextView shipping;
TextView taxes;
TextView totals;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cart);
View header = getLayoutInflater().inflate(R.layout.activity_cart, null);
//ListView.addHeaderView(headerView);
user = MainActivity.currentAccount.getUsername();
if(user == null || user.equals("Guest")) {
shipCost = (float)0.00;
tax = (float)0.00;
}
if(user != null && !(user.equals("Guest"))) {
new getCartIcon().execute();
//View header = getLayoutInflater().inflate(R.layout.activity_cart, null);
//View footer = getLayoutInflater().inflate(R.layout.activity_search, null);
ListView listView = (ListView) findViewById(R.id.list_cart_view);
new returnCartItems().execute();
//if (!(cartItems.isEmpty())) {
adaptCart = new ProductsAdapter(Cart.this, 0, cartItems);
listView.setOnItemClickListener(new ListView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
try {
ProductsAdapter.ViewHolder holder = new ProductsAdapter.ViewHolder();
holder.product_name = (TextView) v.findViewById(R.id.product_name);
holder.product_dept = (TextView) v.findViewById(R.id.product_dept);
holder.product_desc = (TextView) v.findViewById(R.id.product_desc);
holder.product_price = (TextView) v.findViewById(R.id.product_price);
holder.product_qty = (TextView) v.findViewById(R.id.product_qty);
holder.product_img = (ImageView) findViewById(R.id.icon);
URI = "http://www.michaelscray.com/Softwear/graphics/";
String dept = "Dept: ";
String money = "$";
String qty = "Qty: ";
URI += cartItems.get(position).getProduct_img();
Uri uris = Uri.parse(URI + cartItems.get(position).getProduct_img());
URI uri = java.net.URI.create(URI);
holder.product_name.setText(cartItems.get(position).getProduct_name());
holder.product_desc.setText(cartItems.get(position).getProduct_desc());
holder.product_dept.setText(dept + cartItems.get(position).getProduct_dept());
holder.product_price.setText(money + String.valueOf(cartItems.get(position).getPrice()));
holder.product_qty.setText(qty + String.valueOf(cartItems.get(position).getProduct_qty()));
Picasso.with(getApplicationContext()).load(URI).error(R.mipmap.ic_launcher).into(holder.product_img);
} catch (Exception e) {
e.printStackTrace();
}
}
});
listView.setAdapter(adaptCart);
//}
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.menu_main, menu);
this.menu = menu;
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// toggle nav drawer on selecting action bar app icon/title
return true;
}
public class getCartIcon extends AsyncTask<Void, Void, Void> {
String tempUser = user;
int cartNum = 0;
float tempTotal;
#Override
protected void onPreExecute() {
subTotal = (TextView) findViewById(R.id.textView_subTotal);
shipping = (TextView) findViewById(R.id.textView_shipping);
totals = (TextView) findViewById(R.id.textView_total);
taxes = (TextView) findViewById(R.id.textView_taxes);
}
#Override
protected Void doInBackground(Void... arg0) {
if(tempUser != null) {
try {
Connection conn = ConnectDB.getConnection();
String queryString = "SELECT * FROM Orders WHERE `User_Name` = '" + tempUser + "'";
PreparedStatement st = conn.prepareStatement(queryString);
//st.setString(1, tempUser);
final ResultSet result = st.executeQuery(queryString);
while (result.next()) {
try {
tempTotal += result.getFloat("Price");
//skus.add(result.getInt("SKU"));
} catch(SQLException e) {
e.printStackTrace();
}
cartNum++;
//setTotal(result.getFloat(String.valueOf("Price")));
}
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
protected void onPostExecute(Void result) {
getCartItems(cartNum);
subTotal.setText(String.valueOf(tempTotal));
shipping.setText(String.valueOf(shipCost));
tax = tempTotal * tax;
taxes.setText(String.valueOf(tax));
totals.setText(String.valueOf(tempTotal + shipCost + tax));
//setTotal(tempTotal);
//super.onPostExecute(result);
}
}
public class returnCartItems extends AsyncTask<Void, Void, Void> {
String tempUser = user;
Product product = null;
List<Integer> skus = new ArrayList<>();
//String descr = "DETAILS: \n\n";
#Override
protected void onPreExecute() {
}
#Override
protected Void doInBackground(Void... arg0) {
if(tempUser != null) {
try {
Connection conn = ConnectDB.getConnection();
String queryString = "SELECT * FROM Orders WHERE `User_Name` = '" + tempUser + "'";
PreparedStatement st = conn.prepareStatement(queryString);
//st.setString(1, tempUser);
final ResultSet result = st.executeQuery(queryString);
while (result.next()) {
try {
skus.add(result.getInt("SKU"));
} catch(SQLException e) {
e.printStackTrace();
}
}
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
try {
Connection conn = ConnectDB.getConnection();
String queryString = "SELECT * FROM Inventory";
PreparedStatement st = conn.prepareStatement(queryString);
//st.setString(1, tempUser);
final ResultSet result = st.executeQuery(queryString);
while (result.next()) {
for(int i=0; i < skus.size(); i++) {
if(skus.get(i) == result.getInt("SKU")) {
product = new Product();
product.setProduct_name(result.getString("Name"));
product.setProduct_dept(result.getString("Department"));
product.setProduct_desc(result.getString("Description"));
product.setPrice(result.getFloat("Price"));
product.setProduct_qty(result.getInt("Quantity"));
product.setProduct_img(result.getString("Image"));
cartItems.add(product);
/*
descr += "Product: " + result.getString("Name") + "\n" +
"Department: " + result.getString("Department") + "\n" +
"Price: $" + result.getFloat("Price") + "\n\n";
*/
}
}
}
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
protected void onPostExecute(Void result) {
super.onPostExecute(result);
}
}
public void setTotal(float total) {
this.total += total;
}
public float getTotal() {
return total;
}
public void getCartItems(int cart) {
MenuItem cartMenuItem = (MenuItem) menu.findItem(R.id.action_cart);
if (cart == 0) {
cartMenuItem.setIcon(R.drawable.cart0);
}
if (cart == 1) {
cartMenuItem.setIcon(R.drawable.cart1);
}
if (cart == 2) {
cartMenuItem.setIcon(R.drawable.cart2);
}
if (cart == 3) {
cartMenuItem.setIcon(R.drawable.cart3);
}
if (cart == 4) {
cartMenuItem.setIcon(R.drawable.cart4);
}
if (cart == 5) {
cartMenuItem.setIcon(R.drawable.cart5);
}
if (cart > 5) {
cartMenuItem.setIcon(R.drawable.cart5plus);
}
if (cart > 10) {
cartMenuItem.setIcon(R.drawable.cart10plus);
}
}
}
ProductsAdapter.java:
public class ProductsAdapter extends ArrayAdapter<Product> {
private Activity activity;
private ArrayList<Product> products;
private static LayoutInflater inflater = null;
String money = "$";
String dept = "Dept: ";
String qty ="Qty: ";
static String URI;
public ProductsAdapter(Activity activity, int textViewResourceId, ArrayList<Product> product) {
super(activity, textViewResourceId, product);
try {
this.activity = activity;
this.products = product;
inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//imageLoader = new ImageLoader(activity.getApplicationActivity());
} catch (Exception e) {
return;
}
}
#Override
public int getCount() {
return products.size();
}
public Product getItem(Product position) {
return position;
}
#Override
public long getItemId(int position) {
return position;
}
public static class ViewHolder {
public TextView product_name;
public TextView product_desc;
public TextView product_dept;
public TextView product_price;
public TextView product_qty;
public ImageView product_img;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
final ViewHolder holder;
try {
if(convertView == null) {
vi = inflater.inflate(R.layout.activity_search, parent, false);
holder = new ViewHolder();
holder.product_name = (TextView) vi.findViewById(R.id.product_name);
holder.product_dept = (TextView) vi.findViewById(R.id.product_dept);
holder.product_desc = (TextView) vi.findViewById(R.id.product_desc);
holder.product_price = (TextView) vi.findViewById(R.id.product_price);
holder.product_qty = (TextView) vi.findViewById(R.id.product_qty);
holder.product_img = (ImageView) vi.findViewById(R.id.icon);
vi.setTag(holder);
}
else {
holder = (ViewHolder) vi.getTag();
}
URI = "http://www.michaelscray.com/Softwear/graphics/";
URI += products.get(position).getProduct_img();
Uri uri = Uri.parse(URI + products.get(position).getProduct_img());
holder.product_name.setText(products.get(position).getProduct_name());
holder.product_desc.setText(products.get(position).getProduct_desc());
holder.product_dept.setText(dept + products.get(position).getProduct_dept());
holder.product_price.setText(money + String.valueOf(products.get(position).getPrice()));
holder.product_qty.setText(qty + String.valueOf(products.get(position).getProduct_qty()));
Picasso.with(getContext()).load(URI).error(R.mipmap.ic_launcher).into(holder.product_img);
}
catch(Exception e) {
}
return vi;
}
}
And, activity_cart.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/llSliderCart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#5e80ab"
android:orientation="vertical" >
<TextView
android:id="#+id/summary"
android:layout_width="254dp"
android:layout_height="55dp"
android:gravity="center"
android:text="CART SUMMARY"
android:textColor="#ffffff"
android:textSize="18sp"
android:textStyle="bold"
android:layout_alignParentStart="true"
android:layout_toStartOf="#+id/checkout_btn" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Checkout"
android:id="#+id/checkout_btn"
android:background="#drawable/shape"
android:layout_alignParentBottom="false"
android:layout_alignParentEnd="false"
android:layout_alignParentRight="true"
android:paddingLeft="1dp"
android:paddingTop="1dp"
android:paddingRight="1dp"
android:paddingBottom="1dp"
android:textStyle="bold"
android:textColor="#ffffff" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="#dimen/cart_rows"
android:background="#ffffff"
android:orientation="horizontal" >
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:paddingRight="20dp"
android:text="Subtotal"
android:textColor="#a4a4a4"
android:textSize="#dimen/text_normal" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/vertical_divider_welcome" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:paddingLeft="20dp"
android:text="#string/currency"
android:textColor="#a4a4a4"
android:textSize="#dimen/text_normal" />
<TextView
android:id="#+id/textView_subTotal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:paddingRight="20dp"
android:text="0.00"
android:textColor="#a4a4a4"
android:textSize="#dimen/text_normal" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/vertical_divider_welcome" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="#dimen/cart_rows"
android:background="#ffffff"
android:orientation="horizontal" >
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:paddingRight="20dp"
android:text="Shipping"
android:textColor="#a4a4a4"
android:textSize="#dimen/text_normal" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/vertical_divider_welcome" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:paddingLeft="20dp"
android:text="#string/currency"
android:textColor="#a4a4a4"
android:textSize="#dimen/text_normal" />
<TextView
android:id="#+id/textView_shipping"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:paddingRight="20dp"
android:text="0.00"
android:textColor="#a4a4a4"
android:textSize="#dimen/text_normal" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/vertical_divider_welcome" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="#dimen/cart_rows"
android:background="#ffffff"
android:orientation="horizontal" >
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:paddingRight="20dp"
android:text="Tax"
android:textColor="#a4a4a4"
android:textSize="#dimen/text_normal" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/vertical_divider_welcome" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:paddingLeft="20dp"
android:text="#string/currency"
android:textColor="#a4a4a4"
android:textSize="#dimen/text_normal" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:paddingRight="20dp"
android:text="0"
android:textColor="#a4a4a4"
android:textSize="#dimen/text_normal"
android:id="#+id/textView_taxes" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/vertical_divider_welcome" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="#dimen/cart_rows"
android:background="#ffffff"
android:orientation="horizontal" >
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:paddingRight="20dp"
android:text="Total"
android:textStyle="bold"
android:textColor="#color/blue"
android:textSize="#dimen/text_title" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/vertical_divider_welcome" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:paddingLeft="20dp"
android:text="#string/currency"
android:textStyle="bold"
android:textColor="#color/blue"
android:textSize="#dimen/text_title" />
<TextView
android:id="#+id/textView_total"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:textStyle="bold"
android:paddingRight="20dp"
android:text="0.00"
android:textColor="#color/blue"
android:textSize="#dimen/text_title" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/vertical_divider_welcome" />
<!--
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Description"
android:id="#+id/textView" />
-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Cart contents:"
android:id="#+id/contents"
android:background="#color/vertical_divider_welcome"
android:textStyle="bold|italic"
android:layout_alignParentEnd="false"
android:layout_alignParentStart="false" />
</RelativeLayout>
<ListView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:id="#+id/list_cart_view">
</ListView>
</LinearLayout>
Thanks again!
While your RelativeLayout(the one just before the ListView) have match_parent as height, it will take the remaining space of the window... so there is no place for your ListView to be shown.
Try this..
Give id to the above Relative layout and use the same below.
<ListView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:layout_below="#id/"
android:id="#+id/list_cart_view">
</ListView>
Related
I done video playing inside recyclerview with cardview using sdcard path location. Also check sdcard not available then fetch recorded videos from internal memory. Its perfectly working in Lava iris x8 device, but in Samsung J5 and Samsung Note 2 only odd numbers(1,3,5,7) videos are playing not even(2,4,6,8) videos are playing and getting dialog like "Can't play this video" when scrolling and getting position of even(2,4,6,8) numbers of video. I am not able to know what is the problem? Below is my whole code about display and play video inside recyclerview and cardview in android.
display_video.xml
<?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="#FFFFFF"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/mRelative_background"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:background="#6FC298">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp">
<RelativeLayout
android:id="#+id/mRelativeClick"
android:layout_width="50dp"
android:layout_height="30dp"
android:gravity="left">
<ImageView
android:id="#+id/mImage_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#mipmap/icon_back"></ImageView>
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="My Challenge"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:textStyle="italic" />
<ImageView
android:id="#+id/mImageView_setting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="#mipmap/icon_setting"></ImageView>
</RelativeLayout>
<RelativeLayout
android:id="#+id/mRelative_circular_image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="65dp">
<ImageView
android:id="#+id/mImageView_color1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:visibility="invisible"
android:layout_marginLeft="10dp"
android:src="#mipmap/color1"/>
<ImageView
android:id="#+id/mImageView_color2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:visibility="invisible"
android:layout_toRightOf="#+id/mImageView_color1"
android:src="#mipmap/color2"/>
<ImageView
android:id="#+id/mImageView_color3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:visibility="invisible"
android:layout_toRightOf="#+id/mImageView_color2"
android:src="#mipmap/color3"/>
<app.stakes.CircularImageView
android:id="#+id/mcircularImage"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_centerInParent="true"
android:background="#mipmap/camera_icon" />
<ImageView
android:id="#+id/mImageView_color4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:visibility="invisible"
android:layout_toRightOf="#+id/mcircularImage"
android:src="#mipmap/color4"/>
<ImageView
android:id="#+id/mImageView_color5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:visibility="invisible"
android:layout_toRightOf="#+id/mImageView_color4"
android:src="#mipmap/color5"/>
<ImageView
android:id="#+id/mImageView_color6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:visibility="invisible"
android:layout_toRightOf="#+id/mImageView_color5"
android:src="#mipmap/color6"/>
</RelativeLayout>
<TextView
android:id="#+id/mTextViewUsername_VideoList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/mRelative_circular_image"
android:layout_centerInParent="true"
android:layout_marginTop="25dp"
android:text="Text"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:textStyle="italic" />
<ImageView
android:id="#+id/mImageView_color_table"
android:src="#mipmap/color_table"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/mRelative_circular_image"
android:layout_marginTop="25dp"
android:layout_marginRight="15dp"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/mRelativeTab"
android:layout_below="#+id/mRelative_background"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/mImageViewtab2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/list"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<ImageView
android:id="#+id/mImageViewtab1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/view"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="40dp"
android:layout_marginStart="40dp" />
<ImageView
android:id="#+id/mImageViewtab3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/showbook"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginRight="40dp"
/>
</RelativeLayout>
<RelativeLayout
android:layout_below="#+id/mRelativeTab"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/my_recycler_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:scrollbars="vertical" />
</RelativeLayout>
</RelativeLayout>
cardview1.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
card_view:cardCornerRadius="5dp"
card_view:cardUseCompatPadding="true">
<RelativeLayout
android:background="#FFFFFF"
android:id="#+id/mRelativeMain"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--<ImageView
android:id="#+id/iconId"
android:layout_width="300dp"
android:layout_height="250dp"
android:layout_centerHorizontal="true"/>-->
<app.stakes.CircularImageView
android:id="#+id/circleImageview"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:background="#mipmap/camera_icon" />
<TextView
android:id="#+id/tvVersionName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_toRightOf="#+id/circleImageview"
android:layout_marginLeft="5dp"
android:text="Auther"
android:textColor="#android:color/black"
android:textSize="7sp" />
<TextView
android:id="#+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_toRightOf="#+id/circleImageview"
android:layout_marginLeft="70dp"
android:textColor="#android:color/black"
android:textSize="10sp" />
<ImageView
android:id="#+id/mImageview_clock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_toLeftOf="#+id/tvSec"
android:src="#mipmap/timing"/>
<TextView
android:id="#+id/tvSec"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:layout_marginTop="35dp"
android:text="Lollipop"
android:textColor="#android:color/black"
android:textSize="5sp" />
<FrameLayout
android:id="#+id/video_frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/circleImageview">
<com.sprylab.android.widget.TextureVideoView
android:id="#+id/mvideoView"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_marginTop="10dp"
android:layout_gravity="center_horizontal|center_vertical"
/>
<ImageView
android:id="#+id/mImageview_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:src="#mipmap/play" />
<ImageView
android:id="#+id/mImageView_fav"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/mImageview_play"
android:layout_gravity="left|center_vertical"
android:layout_marginLeft="40dp"
android:layout_marginTop="130dp"
android:src="#mipmap/bookmark_video" />
<ImageView
android:id="#+id/mImageView_share"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_below="#+id/mImageview_play"
android:layout_gravity="right|center_vertical"
android:layout_marginRight="40dp"
android:layout_marginTop="130dp"
android:src="#mipmap/sharevideo" />
<!--</RelativeLayout>-->
</FrameLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
Display_Video1.java
public class Display_Video1 extends ActionBarActivity {
public RecyclerView recyclerView;
private ArrayList<FeddProperties> os_versions;
private Adapter mAdapter;
private Adapter fav_video_adapter;
CircularImageView mcircularImage;
static DisplayMetrics dm;
static MediaController media_Controller;
RelativeLayout mRelativeClick;
static boolean isViewWithCatalog;
RelativeLayout mRelative_background;
static File OldFile;
static String[] fileList = null;
static String[] fileListOld = null;
/*static String FILE_PATH = newFile.getAbsolutePath();*/
static String FILEPATH_OLD;
static String videoOldFilePath;
static String replaceOldString;
String MiME_TYPE = "video/mp4";
static String videoFilePath;
static String replaceStr;
static String[] fav_video_list = null;
CallbackManager callbackManager;
public static String facebook_user_id;
public static String username;
Boolean isSDPresent;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.display_video);
isSDPresent = android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
if(isSDPresent) {
OldFile = new File(Environment.getExternalStorageDirectory(), "/Stakes_Download");
MEDIA_PATHOLD = new String(OldFile.getAbsolutePath());
FILEPATH_OLD = OldFile.getAbsolutePath();
}
else{
OldFile = new File(this.getFilesDir(), "Stakes_Download");
MEDIA_PATHOLD = new String(OldFile.getAbsolutePath());
FILEPATH_OLD = OldFile.getAbsolutePath();
}
recyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
os_versions = new ArrayList<FeddProperties>();
if (fileList != null) {
for (int i = 0; i < fileList.length; i++) {
if (fileList[i].length() == 0) {
ArrayList<Integer> alist = new ArrayList<Integer>();
alist.add(fileList.length);
Toast.makeText(getApplicationContext(), "File Zero: " + Arrays.toString(fileList), Toast.LENGTH_LONG).show();
}
}
}
if (fileListOld != null) {
for (int i = 0; i < fileListOld.length; i++) {
if (fileListOld[i].length() == 0) {
ArrayList<Integer> alist = new ArrayList<Integer>();
alist.add(fileListOld.length);
Toast.makeText(getApplicationContext(), "File Zero: " + Arrays.toString(fileListOld), Toast.LENGTH_LONG).show();
}
}
}
recyclerView.setHasFixedSize(true);
// ListView
recyclerView.setLayoutManager(new LinearLayoutManager(Display_Video1.this));
// create an Object for Adapter
if (fileList != null) {
mAdapter = new CardViewDataAdapter(Display_Video1.this, fileList);
// set the adapter object to the Recyclerview
recyclerView.setAdapter(mAdapter);
} else {
/*Toast.makeText(getApplicationContext(),"No File Exist",Toast.LENGTH_LONG).show();*/
}
updateSongList();
updateSongListOld();
initContrls();
}
public void updateSongList() {
File videoFiles = new File(MEDIA_PATHOLD);
Log.d("**Value of videoFiles**", videoFiles.toString());
if (videoFiles.isDirectory()) {
fileList = videoFiles.list();
}
if (fileList == null) {
System.out.println("File doesnot exit");
Toast.makeText(this, "There is no file", Toast.LENGTH_SHORT).show();
} else {
System.out.println("fileList****************" + fileList);
for (int i = 0; i < fileList.length; i++) {
Log.e("Video:" + i + " File name", fileList[i]);
}
}
}
public void updateSongListOld() {
File videoFiles = new File(MEDIA_PATHOLD);
Log.d("**Value of videoFiles**", videoFiles.toString());
if (videoFiles.isDirectory()) {
fileListOld = videoFiles.list();
}
if (fileListOld == null) {
System.out.println("File doesnot exit");
Toast.makeText(this, "There is no file", Toast.LENGTH_SHORT).show();
} else {
System.out.println("fileList****************" + fileListOld);
for (int i = 0; i < fileListOld.length; i++) {
Log.e("Video:" + i + " File name", fileListOld[i]);
}
}
}
private void initContrls() {
recyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
os_versions = new ArrayList<FeddProperties>();
if (fileList != null) {
/*gridView.setAdapter(new ImageAdapter(this, fileList));*/
for (int i = 0; i < fileList.length; i++) {
if (fileList[i].length() == 0) {
ArrayList<Integer> alist = new ArrayList<Integer>();
alist.add(fileList.length);
Toast.makeText(getApplicationContext(), "File Zero: " + Arrays.toString(fileList), Toast.LENGTH_LONG).show();
/* FeddProperties feed = new FeddProperties();
feed.setTitle(fileList[i]);
*//*feed.setThumbnail(icons[i]);*//*
os_versions.add(feed);*/
}
}
}
if (fileListOld != null) {
/*gridView.setAdapter(new ImageAdapter(this, fileList));*/
for (int i = 0; i < fileListOld.length; i++) {
if (fileListOld[i].length() == 0) {
ArrayList<Integer> alist = new ArrayList<Integer>();
alist.add(fileListOld.length);
Toast.makeText(getApplicationContext(), "File Zero: " + Arrays.toString(fileListOld), Toast.LENGTH_LONG).show();
/* FeddProperties feed = new FeddProperties();
feed.setTitle(fileList[i]);
*//*feed.setThumbnail(icons[i]);*//*
os_versions.add(feed);*/
}
}
}
recyclerView.setHasFixedSize(true);
// ListView
recyclerView.setLayoutManager(new LinearLayoutManager(this));
//Grid View
/* recyclerView.setLayoutManager(new GridLayoutManager(this,2,1,false));*/
//StaggeredGridView
/*recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2,1));*/
// create an Object for Adapter
if (fileList != null) {
mAdapter = new CardViewDataAdapter(Display_Video1.this, fileList);
// set the adapter object to the Recyclerview
recyclerView.setAdapter(mAdapter);
} else {
/*Toast.makeText(getApplicationContext(),"No File Exist",Toast.LENGTH_LONG).show();*/
}
recyclerView.addOnItemTouchListener(new CardViewDataAdapter(Display_Video1.this, new CardViewDataAdapter.OnItemClickListener() {
#Override
public void onItemClick(View view, int position) {
}
}));
}
Recyclerview Adapter
public static class CardViewDataAdapter extends Adapter<CardViewDataAdapter.ViewHolder> implements OnItemTouchListener {
private ArrayList<FeddProperties> dataSet;
private OnItemClickListener mListener;
GestureDetector mGestureDetector;
private Context context;
private String[] VideoValues;
private int position = 0;
public interface OnItemClickListener {
public void onItemClick(View view, int position);
}
public CardViewDataAdapter(Context context, String[] VideoValues) {
/*dataSet = os_versions;*/
this.context = context;
this.VideoValues = VideoValues;
}
public CardViewDataAdapter(Context context, OnItemClickListener listener) {
mListener = listener;
mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
#Override
public boolean onSingleTapUp(MotionEvent e) {
return true;
}
});
}
#Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
// create a new view
View itemLayoutView = LayoutInflater.from(viewGroup.getContext()).inflate(
R.layout.card_view1, null);
ViewHolder viewHolder = new ViewHolder(itemLayoutView);
return viewHolder;
}
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
#Override
public void onBindViewHolder(final ViewHolder viewHolder, final int i) {
videoFilePath = FILEPATH_OLD + "/" + fileList[i];
Toast.makeText(context,"Path: "+videoFilePath,Toast.LENGTH_LONG).show();
viewHolder.tvVersionName.setText(fileList[i]);
System.out
.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>> file path>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
+ fileList[i]);
viewHolder.mvideoView.setVideoPath(videoFilePath);
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(context, Uri.parse(videoFilePath));
final String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
long timeInMillisec = Long.parseLong(time);
final long duration = timeInMillisec / 1000;
long hours = duration / 3600;
long minutes = (duration - hours * 3600) / 60;
final long seconds = duration - (hours * 3600 + minutes * 60);
viewHolder.tvSec.setText(String.valueOf(seconds) + "s");
viewHolder.mImageview_play.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (viewHolder.mvideoView!= null) {
if (viewHolder.mvideoView.isPlaying()) {
viewHolder.mvideoView.pause();
viewHolder.mImageview_play.setImageResource(R.mipmap.play);
} else {
viewHolder.mvideoView.start();
viewHolder.mImageview_play.setImageResource(R.mipmap.play_click);
}
}
viewHolder.mvideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mp) {
viewHolder.mImageview_play.setImageResource(R.mipmap.play);
}
});
}
});
viewHolder.str = fileList;
}
#Override
public int getItemCount() {
return VideoValues.length;
}
#Override
public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent e) {
View childView = recyclerView.findChildViewUnder(e.getX(), e.getY());
if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) {
mListener.onItemClick(childView, recyclerView.getChildAdapterPosition(childView));
}
return false;
}
#Override
public void onTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) {
}
#Override
public void onRequestDisallowInterceptTouchEvent(boolean b) {
}
// inner class to hold a reference to each item of RecyclerView
public class ViewHolder extends RecyclerView.ViewHolder {
public TextView tvVersionName;
public TextView tvTitle;
public TextView tvSec;
/*public ImageView iconView;*/
/*public RelativeLayout mvideoView;*/
public TextureVideoView mvideoView;
public ImageView mImageview_play;
public CircularImageView circleImageview;
public ImageView mImageView_fav;
public ImageView mImageView_share;
public FeddProperties feed;
public String[] str;
public ViewHolder(View itemLayoutView) {
super(itemLayoutView);
tvVersionName = (TextView) itemLayoutView
.findViewById(R.id.tvVersionName);
/*iconView = (ImageView) itemLayoutView
.findViewById(R.id.iconId);*/
tvSec = (TextView) itemLayoutView.findViewById(R.id.tvSec);
tvTitle = (TextView) itemLayoutView.findViewById(R.id.tvTitle);
mvideoView = (TextureVideoView) itemLayoutView.findViewById(R.id.mvideoView);
mImageview_play = (ImageView) itemLayoutView.findViewById(R.id.mImageview_play);
}
}
}
I've been looking around but I can't figure out how I can fixed this issue.
I'm using the #Dave Morrissey's Subsampling Zoom Image View, is a great library and it works perfect, but I want to do a few changes.
For each image that the user will slide I want show the specific description.
So it will be:
Pic1 |Pic2 |Pic3
DescriptionPic1 |DescriptionPic2 |DescriptionPic3
When I open it I can see the picture with below the right description but when I slide left(or right) I can see always the description of the item after.
Happens because the method getItem() get called twice to make the slider more smooth.
The problem is that I want show the right content(description) below each picture.
How can I show the content perfectly when the user slide the pics?
Any help is really appreciate.
Thanks guys
ViewPagerActivity.java
public class ViewPagerActivity extends FragmentActivity {
private ViewPager page;
private Bitmap bmImg1;
private Bitmap bmImg2;
private Bitmap bmImg3;
private String TAG;
ArrayList<Bitmap> IMAGES =new ArrayList<Bitmap>();
String[] descriptionPhoto;
int numpics=1;
private int position_pic;
private String suggested_aperture;
private String suggested_filter;
private String suggested_iso;
private String suggested_shutter;
private String suggested_shot_level;
private String suggested_lens;
private String[] shot_levelPhoto;
private String[] filterPhoto;
private String[] aperturePhoto;
private String[] shutterPhoto;
private String[] isoPhoto;
private String[] focal_lengthPhoto;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_pager);
FileInputStream fis;
FileInputStream fis2;
FileInputStream fis3;
Bundle intent=getIntent().getExtras();
descriptionPhoto = intent.getStringArray("descriptionPhoto");
numpics = (int) intent.get("numpics");
position_pic = (int) intent.get("position_pic");
suggested_aperture= intent.getString("suggested_aperture");
suggested_filter= intent.getString("suggested_filter");
suggested_iso= intent.getString("suggested_iso");
suggested_shutter= intent.getString("suggested_shutter");
suggested_shot_level= intent.getString("suggested_shot_level");
suggested_lens= intent.getString("suggested_lens");
shot_levelPhoto=intent.getStringArray("shot_levelPhoto");
filterPhoto =intent.getStringArray("filterPhoto");
aperturePhoto =intent.getStringArray("aperturePhoto");
shutterPhoto =intent.getStringArray("shutterPhoto");
isoPhoto =intent.getStringArray("isoPhoto");
focal_lengthPhoto=intent.getStringArray("focal_lengthPhoto");
TextView txtaperture_suggested = (TextView) findViewById(R.id.aperture_suggested);
TextView txtfilter_suggested = (TextView) findViewById(R.id.filter_suggested);
TextView txtiso_suggested = (TextView) findViewById(R.id.iso_suggested);
TextView txtlens_suggested = (TextView) findViewById(R.id.lens_suggested);
TextView txtshutter_suggested = (TextView) findViewById(R.id.shutter_suggested);
TextView txtshot_levelsuggested = (TextView) findViewById(R.id.shot_levelsuggested);
if (suggested_shot_level == "1") {
txtshot_levelsuggested.setText("Easy");
/*txtshot_levelPhoto2.setText("Easy");
txtshot_levelPhoto3.setText("Easy");*/
} else if (suggested_shot_level == "2") {
txtshot_levelsuggested.setText("Medium");
/* txtshot_levelPhoto2.setText("Medium");
txtshot_levelPhoto3.setText("Medium");*/
} else if (suggested_shot_level == "3") {
txtshot_levelsuggested.setText("Difficult");
/*txtshot_levelPhoto2.setText("Difficult");
txtshot_levelPhoto3.setText("Difficult");*/
} else {
txtshot_levelsuggested.setText("Pro");
/* txtshot_levelPhoto2.setText("Pro");
txtshot_levelPhoto3.setText("Pro");*/
}
txtaperture_suggested.setText(suggested_aperture);
txtfilter_suggested.setText(suggested_filter);
txtiso_suggested.setText(suggested_iso);
txtshutter_suggested.setText(suggested_shutter);
txtlens_suggested.setText(suggested_lens);
TextView txtshutterPhoto = (TextView) findViewById(R.id.shutterPhoto);
TextView txtshutterPhoto2 = (TextView) findViewById(R.id.shutterPhoto2);
TextView txtshutterPhoto3 = (TextView) findViewById(R.id.shutterPhoto3);
TextView txtshot_levelPhoto = (TextView) findViewById(R.id.shot_levelPhoto);
TextView txtshot_levelPhoto2 = (TextView) findViewById(R.id.shot_levelPhoto2);
TextView txtshot_levelPhoto3 = (TextView) findViewById(R.id.shot_levelPhoto3);
TextView txtaperturePhoto = (TextView) findViewById(R.id.aperturePhoto);
TextView txtaperturePhoto2 = (TextView) findViewById(R.id.aperturePhoto2);
TextView txtaperturePhoto3 = (TextView) findViewById(R.id.aperturePhoto3);
TextView txtfilterPhoto = (TextView) findViewById(R.id.filterPhoto);
TextView txtfilterPhoto2 = (TextView) findViewById(R.id.filterPhoto2);
TextView txtfilterPhoto3 = (TextView) findViewById(R.id.filterPhoto3);
TextView txtisoPhoto = (TextView) findViewById(R.id.isoPhoto);
TextView txtisoPhoto2 = (TextView) findViewById(R.id.isoPhoto2);
TextView txtisoPhoto3 = (TextView) findViewById(R.id.isoPhoto3);
TextView txtlensPhoto = (TextView) findViewById(R.id.lensPhoto);
TextView txtlensPhoto2 = (TextView) findViewById(R.id.lensPhoto2);
TextView txtlensPhoto3 = (TextView) findViewById(R.id.lensPhoto3);
/*txtshutterPhoto.setText(shutterPhoto[0]);
if (shutterPhoto.length > 1) {
txtshutterPhoto2.setText(shutterPhoto[1]);
if (shutterPhoto.length > 2) {
txtshutterPhoto3.setText(shutterPhoto[2]);
}
}
txtisoPhoto.setText(isoPhoto[0]);
if (isoPhoto.length > 1) {
txtisoPhoto2.setText(isoPhoto[1]);
if (isoPhoto.length > 2) {
txtisoPhoto3.setText(isoPhoto[2]);
}
}
txtfilterPhoto.setText(filterPhoto[0]);
if (filterPhoto.length > 1) {
txtfilterPhoto2.setText(filterPhoto[1]);
if ((filterPhoto.length > 2)) {
txtfilterPhoto3.setText(filterPhoto[2]);
}
}
txtaperturePhoto.setText(aperturePhoto[0]);
if (aperturePhoto.length > 1) {
txtaperturePhoto2.setText(aperturePhoto[1]);
if (aperturePhoto.length > 2) {
txtaperturePhoto3.setText(aperturePhoto[2]);
}
}*/
try {
fis = getApplicationContext().openFileInput("bmImg1");
bmImg1 = BitmapFactory.decodeStream(fis);
IMAGES.add(bmImg1);
fis.close();
/*
findViewById(R.id.note1).setVisibility(View.VISIBLE);
TextView descriptionnote = (TextView)findViewById(R.id.note1);
descriptionnote.setText(descriptionPhoto[0]);
*/
if(numpics>1){
fis2 = getApplicationContext().openFileInput("bmImg2");
bmImg2 = BitmapFactory.decodeStream(fis2);
IMAGES.add(bmImg2);
fis2.close();
/*
findViewById(R.id.note1).setVisibility(View.INVISIBLE);
findViewById(R.id.note2).setVisibility(View.VISIBLE);
TextView descriptionnote2 = (TextView)findViewById(R.id.note2);
descriptionnote2.setText(descriptionPhoto[1]);
*/
if(numpics>2){
fis3 = getApplicationContext().openFileInput("bmImg3");
bmImg3 = BitmapFactory.decodeStream(fis3);
IMAGES.add(bmImg3);
fis3.close();
/*
findViewById(R.id.note2).setVisibility(View.INVISIBLE);
findViewById(R.id.note3).setVisibility(View.VISIBLE);
TextView descriptionnote3 = (TextView)findViewById(R.id.note3);
descriptionnote3.setText(descriptionPhoto[2]);
*/
}
}
}
catch (FileNotFoundException e) {
Log.d(TAG, "file not found");
e.printStackTrace();
}
catch (IOException e) {
Log.d(TAG, "io exception");
e.printStackTrace();
}
PagerAdapter pagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
page = (ViewPager)findViewById(R.id.pager);
page.setAdapter(pagerAdapter);
page.setCurrentItem(position_pic);
if(page.getCurrentItem()==0 ){
findViewById(R.id.note1).setVisibility(View.VISIBLE);
findViewById(R.id.note2).setVisibility(View.INVISIBLE);
findViewById(R.id.note3).setVisibility(View.INVISIBLE);
TextView descriptionnote = (TextView) findViewById(R.id.note1);
descriptionnote.setText(descriptionPhoto[0]);
}
if (page.getCurrentItem()==1 ) {
findViewById(R.id.note1).setVisibility(View.INVISIBLE);
findViewById(R.id.note2).setVisibility(View.VISIBLE);
findViewById(R.id.note3).setVisibility(View.INVISIBLE);
TextView descriptionnote2 = (TextView) findViewById(R.id.note2);
descriptionnote2.setText(descriptionPhoto[1]);
}
if (page.getCurrentItem()==2 ) {
findViewById(R.id.note1).setVisibility(View.INVISIBLE);
findViewById(R.id.note2).setVisibility(View.INVISIBLE);
findViewById(R.id.note3).setVisibility(View.VISIBLE);
TextView descriptionnote3 = (TextView) findViewById(R.id.note3);
descriptionnote3.setText(descriptionPhoto[2]);
}
}
#Override
public void onBackPressed() {
super.onBackPressed();
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
finish();
return true;
}
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
public ScreenSlidePagerAdapter(FragmentManager fm) {
super(fm);
}
public int getItemPosition(Object item){
return POSITION_NONE;
}
#Override
public Fragment getItem(int position) {
ViewPagerFragment fragment = new ViewPagerFragment();
fragment.setAsset(IMAGES.get(position));
return fragment;
}
#Override
public int getCount() {
return IMAGES.size();
}
}}
This is the ViewPagerFragment
public class ViewPagerFragment extends Fragment {
private static final String BUNDLE_ASSET = "res";
private Bitmap asset;
public ViewPagerFragment() {
}
public void setAsset(Bitmap asset) {
this.asset = asset;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.view_pager_page, container, false);
/* if (savedInstanceState != null) {
if (asset == null && savedInstanceState.containsKey(BUNDLE_ASSET)) {
asset = savedInstanceState.getParcelable(BUNDLE_ASSET);
}
}*/
if (asset != null) {
SubsamplingScaleImageView imageView = (SubsamplingScaleImageView)rootView.findViewById(R.id.imageView);
imageView.setImage(ImageSource.bitmap(asset));
}
return rootView;
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
View rootView = getView();
if (rootView != null) {
outState.putString(BUNDLE_ASSET, String.valueOf(asset));
}
}}
ViewPager.xml
<?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:id="#+id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#333">
<GridLayout
android:id="#+id/suggestedParameter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="visible"
android:paddingTop="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:layout_below="#+id/textParameter"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TextView
android:id="#+id/shot_levellabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/shot_levellabel"
android:layout_weight="0.10"
android:gravity="center"
android:layout_row="0"
android:layout_column="0"
android:textColor="#ffffff" />
<TextView
android:id="#+id/shot_levelsuggested"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:textColor="#90c683"
android:layout_weight="0.10"
android:layout_row="1"
android:layout_column="0"
android:textColorHint="#ffffff" />
<TextView
android:id="#+id/shot_levelPhoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_weight="0.10"
android:layout_row="2"
android:layout_column="0"
android:textColor="#ffffff"
android:textColorHint="#ffffff" />
<!-- <TextView
android:id="#+id/shot_levelPhoto2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_weight="0.10"
android:layout_row="3"
android:layout_column="0" />
<TextView
android:id="#+id/shot_levelPhoto3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_weight="0.10"
android:layout_row="4"
android:layout_column="0" />-->
<TextView
android:id="#+id/shutterPhotolabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/shutterPhotolabel"
android:layout_weight="0.10"
android:layout_row="0"
android:layout_column="1"
android:textColor="#ffffff"
android:textColorHint="#ffffff" />
<TextView
android:id="#+id/shutter_suggested"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:textColor="#90c683"
android:layout_weight="0.10"
android:layout_row="1"
android:layout_column="1"
android:textColorHint="#ffffff" />
<TextView
android:id="#+id/shutterPhoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_weight="0.10"
android:layout_row="2"
android:layout_column="1"
android:textColor="#ffffff"
android:textColorHint="#ffffff" />
<!-- <TextView
android:id="#+id/shutterPhoto2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_weight="0.10"
android:layout_row="3"
android:layout_column="1" />
<TextView
android:id="#+id/shutterPhoto3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_weight="0.10"
android:layout_row="4"
android:layout_column="1" />-->
<TextView
android:id="#+id/aperturePhotolabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/aperturePhotolabel"
android:layout_weight="0.10"
android:layout_row="0"
android:layout_column="2"
android:textColor="#ffffff" />
<TextView
android:id="#+id/aperture_suggested"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:textColor="#90c683"
android:layout_weight="0.10"
android:layout_row="1"
android:layout_column="2"
android:textColorHint="#ffffff" />
<TextView
android:id="#+id/aperturePhoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_weight="0.10"
android:layout_row="2"
android:layout_column="2"
android:textColor="#ffffff"
android:textColorHint="#ffffff" />
<!-- <TextView
android:id="#+id/aperturePhoto2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_weight="0.10"
android:layout_row="3"
android:layout_column="2" />
<TextView
android:id="#+id/aperturePhoto3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_weight="0.10"
android:layout_row="4"
android:layout_column="2" />-->
<TextView
android:id="#+id/isoPhotolabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/isoPhotolabel"
android:layout_weight="0.10"
android:layout_row="0"
android:layout_column="3"
android:textColor="#ffffff" />
<TextView
android:id="#+id/iso_suggested"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:textColor="#90c683"
android:layout_weight="0.10"
android:layout_row="1"
android:layout_column="3"
android:textColorHint="#ffffff" />
<TextView
android:id="#+id/isoPhoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center|right"
android:layout_weight="0.10"
android:paddingRight="10dp"
android:layout_row="2"
android:layout_column="3"
android:textColor="#ffffff"
android:textColorHint="#ffffff" />
<!-- <TextView
android:id="#+id/isoPhoto2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center|right"
android:layout_weight="0.10"
android:paddingRight="10dp"
android:layout_row="3"
android:layout_column="3" />
<TextView
android:id="#+id/isoPhoto3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center|right"
android:layout_weight="0.10"
android:paddingRight="10dp"
android:layout_row="4"
android:layout_column="3" />-->
<TextView
android:id="#+id/lensPhotolabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/lensPhotolabel"
android:layout_weight="0.10"
android:layout_row="0"
android:layout_column="4"
android:textColor="#ffffff" />
<TextView
android:id="#+id/lens_suggested"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center|left"
android:textColor="#90c683"
android:layout_weight="0.10"
android:layout_row="1"
android:layout_column="4"
android:textColorHint="#ffffff" />
<TextView
android:id="#+id/lensPhoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_weight="0.10"
android:layout_row="2"
android:layout_column="4"
android:textColor="#ffffff"
android:textColorHint="#ffffff" />
<!-- <TextView
android:id="#+id/lensPhoto2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_weight="0.10"
android:layout_row="3"
android:layout_column="4"
/>
<TextView
android:id="#+id/lensPhoto3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_weight="0.10"
android:layout_row="4"
android:layout_column="4"
/>-->
<TextView
android:id="#+id/filterPhotolabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/filterPhotolabel"
android:layout_weight="0.10"
android:layout_row="0"
android:layout_column="5"
android:textColor="#ffffff" />
<TextView
android:id="#+id/filter_suggested"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:textColor="#90c683"
android:layout_row="1"
android:layout_column="5"
android:textColorHint="#ffffff" />
<TextView
android:id="#+id/filterPhoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_row="2"
android:layout_column="5"
android:textColor="#ffffff"
android:textColorHint="#ffffff" />
<!-- <TextView
android:id="#+id/filterPhoto2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_row="3"
android:layout_column="5"
/>
<TextView
android:id="#+id/filterPhoto3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_row="4"
android:layout_column="5"
/>-->
</GridLayout>
<!--<TextView
android:id="#+id/parameter_suggested"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="10dp"
android:textSize="14sp"
android:textColor="#FFFFFF"
android:visibility="visible"
/>
<TextView
android:id="#+id/parameter2"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="10dp"
android:textSize="14sp"
android:textColor="#FFFFFF"
android:visibility="invisible"
android:text="456"
android:layout_below="#+id/parameter_suggested"
/>
<TextView
android:id="#+id/parameter3"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="10dp"
android:textSize="14sp"
android:textColor="#FFFFFF"
android:visibility="visible"
android:text="789"
android:layout_below="#+id/parameter_suggested"
/>
-->
</RelativeLayout>
<RelativeLayout
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#333">
<TextView
android:id="#+id/note1"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="10dp"
android:textSize="14sp"
android:textColor="#FFFFFF"
android:visibility="invisible"
/>
<TextView
android:id="#+id/note2"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="10dp"
android:textSize="14sp"
android:textColor="#FFFFFF"
android:visibility="invisible"
/>
<TextView
android:id="#+id/note3"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="10dp"
android:textSize="14sp"
android:textColor="#FFFFFF"
android:visibility="invisible"
/>
</RelativeLayout>
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager"
android:layout_above="#id/text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/text1" />
</RelativeLayout>
you should add image into Map or Array For Reloading:
#Override
public void fill(final Picture picture, int pos, Object... objects) {
image=(ImageView) view.findViewById(R.id.img_galleryadapter_image);
caption=(TextView) view.findViewById(R.id.txt_galleryadapter_caption);
if(bitmapMap.containsKey(picture.imageUrl)){
image.setImageBitmap(bitmapMap.get(picture.imageUrl));
}else {
image.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_hourglass_empty_black_48dp));
Picasso.with(context).load(picture.imageUrl).memoryPolicy(MemoryPolicy.NO_CACHE).skipMemoryCache().into(new Target() {
#Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom loadedFrom) {
image.setImageBitmap(bitmap);
bitmapMap.put(picture.imageUrl, bitmap);
}
#Override
public void onBitmapFailed(Drawable drawable) {}
#Override
public void onPrepareLoad(Drawable drawable) {}
});
}
caption.setText(picture.caption);
}
add to a map:
public static Map<String,Bitmap> bitmapMap=new LinkedHashMap<>();
edit your layout in the xml file to put image then below it a textview using RelativeLayoutor once ur image and its description is aligned its upto ur java codes
After struggling and reading so many different solutions I fixed by myself the issue.
I wanted share with you my solutions maybe can help someone else.
Feel free to ask me everything about it.
This is the FragmentActivity:
public class ViewPagerActivity extends FragmentActivity {
private boolean again=false;
private ViewPager page;
private Bitmap bmImg1;
private Bitmap bmImg2;
private Bitmap bmImg3;
private String TAG;
ArrayList<Bitmap> IMAGES =new ArrayList<>();
ArrayList<String> DESCRIPTIONS =new ArrayList<>();
ArrayList<String> SHOTLEVEL=new ArrayList<>();
ArrayList<String> FILTERPHOTO=new ArrayList<>();
ArrayList<String> APERTUREPHOTO=new ArrayList<>();
ArrayList<String> SHUTTERPHOTO=new ArrayList<>();
ArrayList<String> ISOPHOTO=new ArrayList<>();
ArrayList<String> LENSPHOTO=new ArrayList<>();
String[] descriptionPhoto;
private String shot_levelPhoto;
private String shot_levelPhoto1;
private String shot_levelPhoto2;
private String filterPhoto;
private String filterPhoto1;
private String filterPhoto2;
private String aperturePhoto;
private String aperturePhoto1;
private String aperturePhoto2;
private String shutterPhoto;
private String shutterPhoto1;
private String shutterPhoto2;
private String isoPhoto;
private String isoPhoto1;
private String isoPhoto2;
private String focal_lengthPhoto;
private String focal_lengthPhoto1;
private String focal_lengthPhoto2;
private String[] shot_levelPhotoArray= new String[3];
private String[] filterPhotoArray= new String[3];
private String[] aperturePhotoArray=new String[3];
private String[] shutterPhotoArray=new String[3];
private String[] isoPhotoArray=new String[3];
private String[] focal_lengthPhotoArray=new String[3];
int numpics=1;
private int position_pic;
private String suggested_aperture;
private String suggested_filter;
private String suggested_iso;
private String suggested_shutter;
private String suggested_shot_level;
private String suggested_lens;
private LayoutInflater inflater;
private boolean firsttime;
private boolean secondtime;
private int oldposition=0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_pager);
FileInputStream fis;
FileInputStream fis2;
FileInputStream fis3;
Bundle intent=getIntent().getExtras();
descriptionPhoto = intent.getStringArray("descriptionPhoto");
numpics = (int) intent.get("numpics");
position_pic = (int) intent.get("position_pic");
suggested_aperture= intent.getString("suggested_aperture");
suggested_filter= intent.getString("suggested_filter");
suggested_iso= intent.getString("suggested_iso");
suggested_shutter= intent.getString("suggested_shutter");
suggested_shot_level= intent.getString("suggested_shot_level");
suggested_lens= intent.getString("suggested_lens");
shot_levelPhoto=intent.getString("shot_levelPhoto");
shot_levelPhoto1=intent.getString("shot_levelPhoto1");
shot_levelPhoto2=intent.getString("shot_levelPhoto2");
shot_levelPhotoArray[0] = shot_levelPhoto;
if(!shot_levelPhoto1.equals("null")){
shot_levelPhotoArray[1]=shot_levelPhoto1;
if(!shot_levelPhoto2.equals("null")){
shot_levelPhotoArray[2]=shot_levelPhoto2;
}
}
filterPhoto =intent.getString("filterPhoto");
filterPhoto1 =intent.getString("filterPhoto1");
filterPhoto2 =intent.getString("filterPhoto2");
filterPhotoArray[0]= filterPhoto;
if(!filterPhoto1.equals("null")){
filterPhotoArray[1]=filterPhoto1;
if(!filterPhoto2.equals("null")){
filterPhotoArray[2]=filterPhoto2;
}
}
aperturePhoto =intent.getString("aperturePhoto");
aperturePhoto1 =intent.getString("aperturePhoto1");
aperturePhoto2 =intent.getString("aperturePhoto2");
aperturePhotoArray[0]= aperturePhoto;
if(!aperturePhoto1.equals("null")){
aperturePhotoArray[1]=aperturePhoto1;
if(!aperturePhoto2.equals("null")){
aperturePhotoArray[2]=aperturePhoto2;
}
}
shutterPhoto =intent.getString("shutterPhoto");
shutterPhoto1 =intent.getString("shutterPhoto1");
shutterPhoto2 =intent.getString("shutterPhoto2");
shutterPhotoArray[0]= shutterPhoto;
if(!shutterPhoto1.equals("null")){
shutterPhotoArray[1]=shutterPhoto1;
if(!shutterPhoto2.equals("null")){
shutterPhotoArray[2]=shutterPhoto2;
}
}
isoPhoto =intent.getString("isoPhoto");
isoPhoto1 =intent.getString("isoPhoto1");
isoPhoto2 =intent.getString("isoPhoto2");
isoPhotoArray[0]= isoPhoto;
if(!isoPhoto1.equals("null")){
isoPhotoArray[1]=isoPhoto1;
if(!isoPhoto2.equals("null")){
isoPhotoArray[2]=isoPhoto2;
}
}
focal_lengthPhoto=intent.getString("focal_lengthPhoto");
focal_lengthPhoto1=intent.getString("focal_lengthPhoto1");
focal_lengthPhoto2=intent.getString("focal_lengthPhoto2");
focal_lengthPhotoArray[0]= focal_lengthPhoto;
if(!focal_lengthPhoto1.equals("null")){
focal_lengthPhotoArray[1]=focal_lengthPhoto1;
if(!focal_lengthPhoto2.equals("null")){
focal_lengthPhotoArray[2]=focal_lengthPhoto2;
}
}
TextView txtaperture_suggested = (TextView) findViewById(R.id.aperture_suggested);
TextView txtfilter_suggested = (TextView) findViewById(R.id.filter_suggested);
TextView txtiso_suggested = (TextView) findViewById(R.id.iso_suggested);
TextView txtlens_suggested = (TextView) findViewById(R.id.lens_suggested);
TextView txtshutter_suggested = (TextView) findViewById(R.id.shutter_suggested);
TextView txtshot_levelsuggested = (TextView) findViewById(R.id.shot_levelsuggested);
if (suggested_shot_level == "1") {
txtshot_levelsuggested.setText("Easy");
} else if (suggested_shot_level =="2") {
txtshot_levelsuggested.setText("Medium");
} else if (suggested_shot_level =="3") {
txtshot_levelsuggested.setText("Difficult");
} else if (suggested_shot_level =="4"){
txtshot_levelsuggested.setText("Pro");
}
txtaperture_suggested.setText(suggested_aperture);
txtfilter_suggested.setText(suggested_filter);
txtiso_suggested.setText(suggested_iso);
txtshutter_suggested.setText(suggested_shutter);
txtlens_suggested.setText(suggested_lens);
/* TextView txtshutterPhoto = (TextView) findViewById(R.id.shutterPhoto);
TextView txtshutterPhoto2 = (TextView) findViewById(R.id.shutterPhoto2);
TextView txtshutterPhoto3 = (TextView) findViewById(R.id.shutterPhoto3);
TextView txtshot_levelPhoto = (TextView) findViewById(R.id.shot_levelPhoto);
TextView txtshot_levelPhoto2 = (TextView) findViewById(R.id.shot_levelPhoto2);
TextView txtshot_levelPhoto3 = (TextView) findViewById(R.id.shot_levelPhoto3);
TextView txtaperturePhoto = (TextView) findViewById(R.id.aperturePhoto);
TextView txtaperturePhoto2 = (TextView) findViewById(R.id.aperturePhoto2);
TextView txtaperturePhoto3 = (TextView) findViewById(R.id.aperturePhoto3);
TextView txtfilterPhoto = (TextView) findViewById(R.id.filterPhoto);
TextView txtfilterPhoto2 = (TextView) findViewById(R.id.filterPhoto2);
TextView txtfilterPhoto3 = (TextView) findViewById(R.id.filterPhoto3);
TextView txtisoPhoto = (TextView) findViewById(R.id.isoPhoto);
TextView txtisoPhoto2 = (TextView) findViewById(R.id.isoPhoto2);
TextView txtisoPhoto3 = (TextView) findViewById(R.id.isoPhoto3);
TextView txtfocal_lengthPhoto = (TextView) findViewById(R.id.lensPhoto);
TextView txtfocal_lengthPhoto2 = (TextView) findViewById(R.id.lensPhoto2);
TextView txtfocal_lengthPhoto3 = (TextView) findViewById(R.id.lensPhoto3);*/
/* if (shot_levelPhotoArray[0] == "1") {
txtshot_levelPhoto.setText("Easy");
shot_levelPhotoArray[0] = "Easy";
*//*txtshot_levelPhoto2.setText("Easy");
txtshot_levelPhoto3.setText("Easy");*//*
} else if (shot_levelPhotoArray[0] == "2") {
txtshot_levelPhoto.setText("Medium");
shot_levelPhotoArray[0] = "Medium";
*//* txtshot_levelPhoto2.setText("Medium");
txtshot_levelPhoto3.setText("Medium");*//*
} else if (shot_levelPhotoArray[0] == "3") {
txtshot_levelPhoto.setText("Difficult");
shot_levelPhotoArray[0] = "Difficult";
*//*txtshot_levelPhoto2.setText("Difficult");
txtshot_levelPhoto3.setText("Difficult");*//*
} else {
txtshot_levelPhoto.setText("Pro");
shot_levelPhotoArray[0] = "Pro";
*//* txtshot_levelPhoto2.setText("Pro");
txtshot_levelPhoto3.setText("Pro");*//*
}
txtshutterPhoto.setText(shutterPhoto);
txtisoPhoto.setText(isoPhoto);
txtfilterPhoto.setText(filterPhoto);
txtaperturePhoto.setText(aperturePhoto);
txtfocal_lengthPhoto.setText(focal_lengthPhoto);*/
/*txtshutterPhoto.setText(shutterPhoto[0]);
if (shutterPhoto.length > 1) {
txtshutterPhoto2.setText(shutterPhoto[1]);
if (shutterPhoto.length > 2) {
txtshutterPhoto3.setText(shutterPhoto[2]);
}
}
txtisoPhoto.setText(isoPhoto[0]);
if (isoPhoto.length > 1) {
txtisoPhoto2.setText(isoPhoto[1]);
if (isoPhoto.length > 2) {
txtisoPhoto3.setText(isoPhoto[2]);
}
}
txtfilterPhoto.setText(filterPhoto[0]);
if (filterPhoto.length > 1) {
txtfilterPhoto2.setText(filterPhoto[1]);
if ((filterPhoto.length > 2)) {
txtfilterPhoto3.setText(filterPhoto[2]);
}
}
txtaperturePhoto.setText(aperturePhoto[0]);
if (aperturePhoto.length > 1) {
txtaperturePhoto2.setText(aperturePhoto[1]);
if (aperturePhoto.length > 2) {
txtaperturePhoto3.setText(aperturePhoto[2]);
}
}*/
try {
fis = getApplicationContext().openFileInput("bmImg1");
bmImg1 = BitmapFactory.decodeStream(fis);
IMAGES.add(bmImg1);
DESCRIPTIONS.add(descriptionPhoto[0]);
SHOTLEVEL.add(shot_levelPhotoArray[0]);
FILTERPHOTO.add(filterPhotoArray[0]);
APERTUREPHOTO.add(aperturePhotoArray[0]);
SHUTTERPHOTO.add(shutterPhotoArray[0]);
ISOPHOTO.add(isoPhotoArray[0]);
LENSPHOTO.add(focal_lengthPhotoArray[0]);
fis.close();
if(numpics>1){
fis2 = getApplicationContext().openFileInput("bmImg2");
bmImg2 = BitmapFactory.decodeStream(fis2);
IMAGES.add(bmImg2);
DESCRIPTIONS.add(descriptionPhoto[1]);
SHOTLEVEL.add(shot_levelPhotoArray[1]);
FILTERPHOTO.add(filterPhotoArray[1]);
APERTUREPHOTO.add(aperturePhotoArray[1]);
SHUTTERPHOTO.add(shutterPhotoArray[1]);
ISOPHOTO.add(isoPhotoArray[1]);
LENSPHOTO.add(focal_lengthPhotoArray[1]);
fis2.close();
if(numpics>2){
fis3 = getApplicationContext().openFileInput("bmImg3");
bmImg3 = BitmapFactory.decodeStream(fis3);
IMAGES.add(bmImg3);
DESCRIPTIONS.add(descriptionPhoto[2]);
SHOTLEVEL.add(shot_levelPhotoArray[2]);
FILTERPHOTO.add(filterPhotoArray[2]);
APERTUREPHOTO.add(aperturePhotoArray[2]);
SHUTTERPHOTO.add(shutterPhotoArray[2]);
ISOPHOTO.add(isoPhotoArray[2]);
LENSPHOTO.add(focal_lengthPhotoArray[2]);
fis3.close();
}
}
}
catch (FileNotFoundException e) {
Log.d(TAG, "file not found");
e.printStackTrace();
}
catch (IOException e) {
Log.d(TAG, "io exception");
e.printStackTrace();
}
PagerAdapter pagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager(), descriptionPhoto[position_pic]);
page = (ViewPager)findViewById(R.id.pager);
page.setAdapter(pagerAdapter);
page.setCurrentItem(position_pic);
}
#Override
public void onBackPressed() {
super.onBackPressed();
}
public void clear() {
IMAGES.clear();
DESCRIPTIONS.clear();
SHOTLEVEL.clear();
FILTERPHOTO.clear();
APERTUREPHOTO.clear();
SHUTTERPHOTO.clear();
ISOPHOTO.clear();
LENSPHOTO.clear();
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
finish();
return true;
}
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
String description;
public ScreenSlidePagerAdapter(FragmentManager fm, String description) {
super(fm);
this.description=description;
}
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
super.destroyItem(container, position, object);
}
//this is called when notifyDataSetChanged() is called
#Override
public int getItemPosition(Object object) {
// refresh all fragments when data set changed
return PagerAdapter.POSITION_NONE;
}
#Override
public boolean isViewFromObject(View view, Object object) {
if(object != null){
return ((Fragment)object).getView() == view;
}else{
return false;
}
}
/*#Override
public Fragment getItem(int position) {
ViewPagerFragment fragment = new ViewPagerFragment();
fragment.setAsset(IMAGES.get(position));
return fragment;
}*/
#Override
public Fragment getItem(int index) {
ViewPagerFragment fragment = new ViewPagerFragment();
//fragment.setAsset(IMAGES.get(index));
fragment.setAsset(IMAGES.get(index), DESCRIPTIONS.get(index));
ViewPagerFragment.newInstance(index,
SHOTLEVEL.get(index),
FILTERPHOTO.get(index),
APERTUREPHOTO.get(index),
SHUTTERPHOTO.get(index),
ISOPHOTO.get(index),
LENSPHOTO.get(index)); // Pages is an array of Strings
return fragment;
}
#Override
public int getCount() {
return IMAGES.size();
}
}
}
This is the Fragment
public class ViewPagerFragment extends Fragment {
private static final String BUNDLE_ASSET = "res";
private Bitmap asset;
String descriptionPhoto;
private TextView tv;
HashMap<Bitmap, String > map;
private static Bundle bundle;
public ViewPagerFragment() {
}
/*public int setAsset(Bitmap asset) {
this.asset = asset;
return 0;
}*/
public HashMap<Bitmap, String> setAsset(Bitmap asset, String description){
map= new HashMap<>();
this.asset = asset;
this.descriptionPhoto=description;
map.put(this.asset, this.descriptionPhoto);
return map;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.view_pager_page, container, false);
if (savedInstanceState != null) {
if (asset == null && savedInstanceState.containsKey(BUNDLE_ASSET)) {
asset = savedInstanceState.getParcelable(BUNDLE_ASSET);
}
}
if (asset != null && descriptionPhoto!=null) {
TextView descriptionnote = (TextView) rootView.findViewById(R.id.note1);
if(descriptionPhoto.equals("null")){
descriptionPhoto="No description for this picture";
}
descriptionnote.setText(descriptionPhoto);
SubsamplingScaleImageView imageView = (SubsamplingScaleImageView)rootView.findViewById(R.id.imageView);
imageView.setImage(ImageSource.bitmap(asset));
TextView txtshot_level = (TextView) rootView.findViewById(R.id.shot_levelPhoto);
TextView txtshutterPhoto = (TextView) rootView.findViewById(R.id.shutterPhoto);
TextView txtaperturePhoto = (TextView) rootView.findViewById(R.id.aperturePhoto);
TextView txtfilterPhoto = (TextView) rootView.findViewById(R.id.filterPhoto);
TextView txtisoPhoto = (TextView) rootView.findViewById(R.id.isoPhoto);
TextView txtfocal_lengthPhoto = (TextView) rootView.findViewById(R.id.lensPhoto);
txtshot_level.setText(bundle.getString("shot_levelcontent"));
txtshutterPhoto.setText(bundle.getString("shuttercontent"));
txtisoPhoto.setText(bundle.getString("isocontent"));
txtfilterPhoto.setText(bundle.getString("filtercontent"));
txtaperturePhoto.setText(bundle.getString("aperturecontent"));
txtfocal_lengthPhoto.setText(bundle.getString("lenscontent"));
}
return rootView;
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
View rootView = getView();
if (rootView != null) {
outState.putString(BUNDLE_ASSET, String.valueOf(asset));
}
}
public static Fragment newInstance(int position,
String shot_level,
String filter,
String aperture,
String shutter,
String iso,
String lens) {
ViewPagerFragment swipeFragment = new ViewPagerFragment();
bundle = new Bundle();
if (shot_level.equals("1")) {
bundle.putString("shot_levelcontent", "Easy");
} else if (shot_level.equals("2")) {
bundle.putString("shot_levelcontent", "Medium");
} else if (shot_level.equals("3")) {
bundle.putString("shot_levelcontent", "Difficult");
} else {
bundle.putString("shot_levelcontent", "Pro");
}
bundle.putString("filtercontent", filter);
bundle.putString("aperturecontent", aperture);
bundle.putString("shuttercontent", shutter);
bundle.putString("isocontent", iso);
bundle.putString("lenscontent", lens);
swipeFragment.setArguments(bundle);
return swipeFragment;
}
}
I am having an issue with scrolling of ListView in a Popup. I have an activity that has a dialog theme so that it can open up as a popup. The Popup should contain EditText at the bottom and the remaining area above it should be the ListView. When the activity is started it should start with keypad open & focus on EditText.
Issue: ListView doesn't scroll when keypad is open.
Below is my activity code:
public class CommentsActivity extends Activity{
private InputMethodManager imm;
private String commentCount;
private ShopPirateDatabase db;
private ArrayList<CommentsBean> commentsList = new ArrayList<CommentsBean>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.comments_layout);
imm = (InputMethodManager) this
.getSystemService(Context.INPUT_METHOD_SERVICE);
db=new ShopPirateDatabase(this);
if(getIntent().hasExtra("count")){
commentCount=getIntent().getExtras().getString("count");
}
ListView lvMyComments=(ListView)findViewById(R.id.lvMyComments);
lvMyComments.setVisibility(View.GONE);
final Button btnPost=(Button)findViewById(R.id.btnPost);
btnPost.setVisibility(View.GONE);
etAddComment=(EditText)findViewById(R.id.etAddComment);
RelativeLayout progressLayout=(RelativeLayout)findViewById(R.id.progressLayout);
progressLayout.setVisibility(View.VISIBLE);
TextView tvNoComments=(TextView)findViewById(R.id.tvNoComments);
tvNoComments.setVisibility(View.GONE);
imm.showSoftInput(etAddComment, InputMethodManager.SHOW_IMPLICIT);
if(Integer.parseInt(commentCount) > 0){
getCommentsFromDb();
if(commentsList!=null && commentsList.size() > 0){
progressLayout.setVisibility(View.GONE);
tvNoComments.setVisibility(View.GONE);
lvMyComments.setVisibility(View.VISIBLE);
CommentsAdapter commentsAdapter = new CommentsAdapter(
CommentsActivity.this, commentsList);
lvMyComments.setAdapter(commentsAdapter);
}
} else{
progressLayout.setVisibility(View.GONE);
tvNoComments.setVisibility(View.VISIBLE);
lvMyComments.setVisibility(View.GONE);
}
}
private void getCommentsFromDb() {
db.openDatabase();
Cursor c = db.getComments();
if (c != null) {
commentsList = null;
commentsList = new ArrayList<CommentsBean>();
if (c.moveToFirst()) {
do {
CommentsBean mBeanClass = new CommentsBean();
mBeanClass
.setCommentText(c.getString(c
.getColumnIndex(db.KEY_COMMENT_TEXT)));
mBeanClass
.setCommentedDate(c.getString(c
.getColumnIndex(db.KEY_COMMENT_DATE)));
mBeanClass
.setCommentedBy(c.getString(c
.getColumnIndex(db.KEY_COMMENT_USER)));
commentsList.add(mBeanClass);
} while (c.moveToNext());
}
}
c.close();
db.closeDatabase();
}
}
comments_layout.xml
<RelativeLayout
android:id="#+id/commentsBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="#dimen/margin_5"
android:layout_marginLeft="#dimen/margin_2"
android:layout_marginRight="#dimen/margin_5" >
<Button
android:id="#+id/btnPost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="#dimen/margin_35"
android:background="#color/coupon_color"
android:paddingBottom="#dimen/margin_7"
android:paddingLeft="#dimen/margin_15"
android:paddingRight="#dimen/margin_15"
android:paddingTop="#dimen/margin_7"
android:layout_alignParentRight="true"
android:layout_marginRight="#dimen/margin_2"
android:text="Post"
android:visibility="gone"
android:textColor="#color/white"
android:textSize="#dimen/normal_textsize" />
<EditText
android:id="#+id/etAddComment"
android:layout_width="match_parent"
android:layout_alignParentLeft="true"
android:layout_marginLeft="#dimen/margin_2"
android:layout_toLeftOf="#id/btnPost"
android:layout_marginRight="#dimen/margin_2"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/margin_5"
android:hint="#string/comment_hint" />
</RelativeLayout>
<ListView
android:id="#+id/lvMyComments"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_marginBottom="#dimen/margin_5"
android:divider="#color/home_bg_color"
android:dividerHeight="#dimen/divider_height"
android:scrollbars="none"
android:visibility="gone" >
</ListView>
<RelativeLayout
android:id="#+id/progressLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/commentsBox"
android:layout_marginLeft="#dimen/margin_10"
android:layout_marginRight="#dimen/margin_10" >
<ProgressBar
android:id="#+id/pBarComments"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:indeterminate="true"
android:indeterminateDrawable="#drawable/circular_progress_bar" />
<TextView
android:id="#+id/tvWaitComments"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/pBarComments"
android:layout_centerHorizontal="true"
android:layout_marginLeft="#dimen/margin_5"
android:layout_marginRight="#dimen/margin_5"
android:text="Loading comments..."
android:textColor="#color/black"
android:textSize="#dimen/small_textsize" />
</RelativeLayout>
<TextView
android:id="#+id/tvNoComments"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/etAddComment"
android:layout_marginLeft="#dimen/margin_15"
android:layout_marginRight="#dimen/margin_25"
android:gravity="center_vertical|center_horizontal"
android:text="No comments have been posted for this offer"
android:textColor="#color/black"
android:textSize="#dimen/normal_textsize"
android:visibility="gone" />
CommentsAdapter.java
public class CommentsAdapter extends BaseAdapter {
private Context context;
private ArrayList<CommentsBean> mArrayList = new ArrayList<CommentsBean>();
public CommentsAdapter(Context ctx, ArrayList<CommentsBean> arrayList) {
this.context = ctx;
this.mArrayList = arrayList;
}
#Override
public int getCount() {
return mArrayList.size();
}
#Override
public Object getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view;
view = null;
convertView = null;
if (convertView == null) {
view = new View(context);
view = inflater.inflate(R.layout.list_comments, null);
TextView commentText = (TextView) view
.findViewById(R.id.commentText);
TextView postedDate = (TextView) view.findViewById(R.id.postedDate);
TextView userName = (TextView) view.findViewById(R.id.userName);
commentText.setText(mArrayList.get(position).getCommentText());
userName.setText(" - " + mArrayList.get(position).getCommentedBy());
String dt = mArrayList.get(position).getCommentedDate();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date d = null;
try {
d = sdf.parse(dt);
} catch (ParseException e) {
e.printStackTrace();
}
SimpleDateFormat sdf1 = new SimpleDateFormat("dd-MM-yyyy");
String convertedDate = null;
convertedDate = sdf1.format(d);
postedDate.setText(convertedDate);
}
return view;
}
}
list_comments.xml
<ImageView android:id="#+id/cmtIcon"
android:layout_width="#dimen/margin_25"
android:layout_height="#dimen/margin_25"
android:src="#drawable/comment_list_icon"
android:layout_alignParentTop="true"
android:layout_marginTop="#dimen/margin_5"
android:layout_marginLeft="#dimen/margin_5"
android:layout_alignParentLeft="true" />
<TextView
android:id="#+id/commentText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/margin_10"
android:layout_toRightOf="#id/cmtIcon"
android:layout_alignParentTop="true"
android:layout_marginTop="#dimen/margin_5"
android:textColor="#color/black"
android:textSize="#dimen/normal_textsize" />
<TextView
android:id="#+id/postedDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/commentText"
android:layout_toRightOf="#id/cmtIcon"
android:layout_marginLeft="#dimen/margin_10"
android:layout_marginTop="#dimen/margin_5"
android:text="Posted on"
android:textColor="#color/black"
android:textSize="#dimen/small_textsize" />
<TextView
android:id="#+id/userName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/postedDate"
android:layout_marginTop="#dimen/margin_3"
android:text="User Name"
android:layout_below="#id/commentText"
android:textColor="#color/black"
android:textSize="#dimen/normal_textsize" />
i have an app in which i am retrieving data from json and showing it in listview,i getting an problem only single data is getting visible in the list,i tried to figure out the problem but get nothing,where i am going wrong please help me to sort it out.In log i am getting different data but on adding it to array list getting single data repition multiple time,and no other item is visible.
BussinessActivity
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.bussiness_details);
Log.i("DetailsUrl.Bussinessurl", DetailsUrl);
new JSONAsyncTask().execute(DetailsUrl);
weblink=(TextView)findViewById(R.id.txtweb);
list1 = (ListView) findViewById(R.id.list1);
list1.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long id) {
// TODO Auto-generated method stub
//Toast.makeText(getApplication(),
//catagery.get(position).getcategory_name(),
//Toast.LENGTH_LONG).show();
}
});
}
class JSONAsyncTask extends AsyncTask<String, Void, Boolean> {
ProgressDialog dialog;
#Override
protected void onPreExecute() {
super.onPreExecute();
dialog = new ProgressDialog(BussinessDetails.this);
dialog.setMessage("Loading, please wait");
dialog.setTitle("Connecting server");
dialog.show();
dialog.setCancelable(false);
catageries = new ArrayList<ProfileDetails>();
}
#Override
protected Boolean doInBackground(String... urls) {
try {
// ------------------>>
HttpGet httppost = new HttpGet(urls[0]);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);
// StatusLine stat = response.getStatusLine();
int status = response.getStatusLine().getStatusCode();
if (status == 200) {
HttpEntity entity = response.getEntity();
String data = EntityUtils.toString(entity);
JSONObject jsono = new JSONObject(data);
JSONObject jarray = jsono.getJSONObject("business");
ProfileDetails category = new ProfileDetails();
//String business_id = jarray.getString("business_id");
//Log.i("business_id", business_id);
//String business_name = jarray.getString("business_name");
//Log.i("business_name", business_name);
String web_site = jarray.getString("web_site");
category.setData1(web_site);
category.setNumber2(web_site);
//weblink.setText(web_site);
Log.i("web_site", web_site);
//String about_business = jarray.getString("about_business");
//Log.i("web_site", web_site);
JSONObject phn = jarray.getJSONObject("Phones");
List<String> listArray = new ArrayList<String>();
Iterator iter = phn.keys();
int count=0;
while(iter.hasNext())
{
String key = (String)iter.next();
// listArray.add((String)iter.next());
Log.i("Name",key);
count +=1;
// String key = (String)iter.next();
// Object o = phn.get(key);
if( phn.get(key) instanceof JSONArray ){
JSONArray arry = phn.getJSONArray(key);
int size = arry.length();
for (int i = 0; i < size; i++) {
String CC_info_left = arry.getJSONObject(i).getString("CC_info_left");
Log.i("CC_info_left", CC_info_left);
String CC_info_right = arry.getJSONObject(i).getString("CC_info_right");
Log.i("CC_info_right", CC_info_right);
String CC_info_short_desc = arry.getJSONObject(i).getString("CC_info_short_desc");
Log.i("CC_info_short_desc", CC_info_short_desc);
String CC_info_short_desc_align = arry.getJSONObject(i).getString("CC_info_short_desc_align");
Log.i("CC_info_short_desc_align", CC_info_short_desc_align);
category.setName(key);
category.setNumber1(CC_info_right);
category.setData(CC_info_left);
category.setDescription(CC_info_short_desc);
// Log.i("category", category.toString());
catageries.add(category);
}
}
}
//Collections.sort(listArray);
// System.out.println(listArray);
JSONObject EmailAddress = jarray.getJSONObject("Emails");
Iterator iter1 = EmailAddress.keys();
int count1=0;
while(iter1.hasNext()){
String key1 = (String)iter1.next();
Log.i("Name1",key1);
count +=1;
// String key = (String)iter.next();
// Object o = phn.get(key);
if( EmailAddress.get(key1) instanceof JSONArray ){
JSONArray arry1 = EmailAddress.getJSONArray(key1);
int size1 = arry1.length();
for (int i = 0; i < size1; i++) {
String CC_info_left1 =arry1.getJSONObject(i).getString("CC_info_left");
String CC_info_right1 = arry1.getJSONObject(i).getString("CC_info_right");
String CC_info_short_desc1 = arry1.getJSONObject(i).getString("CC_info_short_desc");
String CC_info_short_desc_align1 =arry1.getJSONObject(i).getString("CC_info_short_desc_align");
category.setEmail(key1);
category.setEmailleft(CC_info_left1);
category.setEmailright(CC_info_right1);
category.setEmailDesc(CC_info_short_desc1);
catageries.add(category);
}
}
}
// /}
// }
return true;
}
// ------------------>>
} catch (ParseException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return false;
}
protected void onPostExecute(Boolean result) {
dialog.cancel();
//adapter.notifyDataSetChanged();
if (result == false){
Toast.makeText(BussinessDetails.this,
"Unable to fetch data from server", Toast.LENGTH_LONG)
.show();
}else{
adapter = new DetailAdaptor(BussinessDetails.this, R.layout.list_details, catageries);
list1.setAdapter(adapter);
//emailAdaptor=new EmailAdaptor(BussinessDetails.this, R.layout.list_details, catagery);
//list2.setAdapter(emailAdaptor);
}
}
}
DetailAdaptor
public class DetailAdaptor extends ArrayAdapter<ProfileDetails> {
ArrayList<ProfileDetails> detailList;
LayoutInflater vi;
int Resource;
ViewHolder holder;
public DetailAdaptor(Context context, int resource, ArrayList<ProfileDetails> objects) {
super(context, resource, objects);
vi = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Resource = resource;
detailList = objects;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// convert view = design
View v = convertView;
if (v == null) {
holder = new ViewHolder();
v = vi.inflate(Resource, null);
holder.tvName = (TextView) v.findViewById(R.id.title_from_phone);
holder.tvData2 = (TextView) v.findViewById(R.id.data_from_phone1);
holder.tvData1 = (TextView) v.findViewById(R.id.data_from_phone2);
holder.tvDescription = (TextView) v.findViewById(R.id.data_from_phone3);
holder.email = (TextView) v.findViewById(R.id.title_for_email);
holder.email_left = (TextView) v.findViewById(R.id.email_left);
holder.email_right = (TextView) v.findViewById(R.id.email_right);
holder.emailDescription = (TextView) v.findViewById(R.id.email_desc);
v.setTag(holder);
}
else{
holder = (ViewHolder) v.getTag();
}
holder.tvName.setText(detailList.get(position).getName());
holder.tvDescription.setText(detailList.get(position).getDescription());
holder.tvData1.setText(detailList.get(position).getNumber1());
holder.tvData2.setText(detailList.get(position).getData());
holder.email.setText(detailList.get(position).getEmail());
holder.email_left.setText(detailList.get(position).getEmailleft());
holder.email_right.setText(detailList.get(position).getEmailright());
holder.emailDescription.setText(detailList.get(position).getEmailDesc());
return v;
}
static class ViewHolder {
public ImageView imageview;
public TextView tvName;
public TextView tvDescription;
public TextView tvData1;
public TextView tvData2;
public TextView email;
public TextView emailDescription;
public TextView email_left;
public TextView email_right;
}
}
ProfileDetails
public class ProfileDetails {
private String title;
private String email;
private String email_left;
private String email_right;
private String email_desc;
private String number1;
private String number2;
private String description;
private String detail1;
private String detail2;
//private String children;
//private String image;
public ProfileDetails() {
// TODO Auto-generated constructor stub
}
public ProfileDetails(String name,String num, String num2, String desc,
String data1, String data2,String emails,String emailleft ,String emailright,String emaildesc) {
super();
title = name;
description = desc;
number1 = num;
number2 = num2;
detail1 = data1;
detail2 = data2;
email =emails;
email_left=emailleft;
email_right=emailright;
email_desc=email_desc;
//this.children = children;
//this.image = image;
}
public String getName() {
return title;
}
public void setName(String name) {
title = name;
}
public String getEmail() {
return email;
}
public void setEmail(String ename) {
email = ename;
}
public String getEmailleft() {
return email_left;
}
public void setEmailleft(String Eleft) {
email_left = Eleft;
}
public String getEmailright() {
return email_right;
}
public void setEmailright(String Eright) {
email_right = Eright;
}
public String getEmailDesc() {
return email_desc;
}
public void setEmailDesc(String Edesc) {
email_desc = Edesc;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getData() {
return detail1;
}
public void setData(String data) {
detail1 = data;
}
public String getData1() {
return detail2;
}
public void setData1(String data) {
detail2 = data;
}
public String getNumber1() {
return number1;
}
public void setNumber1(String num) {
number1 = num;
}
public String getNumber2() {
return number2;
}
public void setNumber2(String num) {
number2 = num;
}
/*public String getSpouse() {
return spouse;
}
public void setSpouse(String spouse) {
this.spouse = spouse;
}
public String getChildren() {
return children;
}
public void setChildren(String children) {
this.children = children;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
*/
}
BussinessDetail.xml
<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:background="#android:color/white"
android:orientation="vertical" >
<View
android:id="#+id/line1"
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:layout_above="#+id/rel1"
android:background="#android:color/darker_gray" />
<RelativeLayout
android:id="#+id/rel1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp" >
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:text="Start a New ChaBu"
android:textColor="#030303"
android:textSize="12dp" />
<ImageView
android:id="#+id/chatIcon"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="20dp"
android:src="#drawable/new_chabu_icon" />
</RelativeLayout>
<View
android:id="#+id/line"
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:layout_below="#+id/rel1"
android:layout_marginTop="10dp"
android:background="#android:color/darker_gray" />
<ListView
android:id="#+id/list1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/line"
android:layout_marginTop="5dp"
android:scrollbars="none"
android:textColor="#android:color/black"
tools:listitem="#layout/list_details" >
</ListView>
</RelativeLayout>
List_details
<?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="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/rel2"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_below="#+id/line"
android:layout_marginTop="10dp"
android:background="#E6E6E6" >
<TextView
android:id="#+id/title1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:text="Customer Care Numbers"
android:textColor="#030303"
android:textSize="15dp"
android:textStyle="bold" />
</RelativeLayout>
<View
android:id="#+id/line4"
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:layout_below="#+id/rel2"
android:layout_marginTop="10dp"
android:background="#android:color/darker_gray" />
<RelativeLayout
android:id="#+id/txtlay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/line4"
android:background="#E6E6E6" >
<TextView
android:id="#+id/title_from_phone"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_marginLeft="10dp"
android:background="#E6E6E6"
android:gravity="center_vertical"
android:text=""
android:textStyle="bold" />
</RelativeLayout>
<View
android:id="#+id/line3"
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:layout_above="#+id/rel1"
android:layout_marginTop="10dp"
android:background="#android:color/darker_gray" />
<RelativeLayout
android:id="#+id/rel1"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_below="#+id/txtlay"
android:background="#E6E6E6" >
<TextView
android:id="#+id/data_from_phone1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="#E6E6E6"
android:gravity="center_vertical"
android:text="" />
<TextView
android:id="#+id/data_from_phone2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:gravity="center_vertical"
android:text="" />
<TextView
android:id="#+id/data_from_phone3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/data_from_phone1"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:text="" />
</RelativeLayout>
<View
android:id="#+id/line1"
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:layout_above="#+id/whitelay"
android:layout_marginTop="10dp"
android:background="#android:color/darker_gray" />
<LinearLayout
android:id="#+id/whitelay"
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_below="#+id/rel1"
android:background="#android:color/white"
android:orientation="vertical" >
</LinearLayout>
<View
android:id="#+id/line2"
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:layout_below="#+id/line1"
android:layout_marginTop="10dp"
android:background="#android:color/darker_gray" />
<RelativeLayout
android:id="#+id/rel3"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_below="#+id/whitelay"
android:visibility="gone"
android:layout_marginTop="10dp"
android:background="#E6E6E6" >
<TextView
android:id="#+id/title3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:text="Customer Care Emails"
android:textColor="#030303"
android:textSize="15dp"
android:textStyle="bold" />
</RelativeLayout>
<View
android:id="#+id/line5"
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:layout_below="#+id/rel3"
android:layout_marginTop="10dp"
android:visibility="gone"
android:background="#android:color/darker_gray" />
<RelativeLayout
android:id="#+id/txtlay1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_below="#+id/line5"
android:background="#E6E6E6" >
<TextView
android:id="#+id/title_for_email"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_marginLeft="10dp"
android:background="#E6E6E6"
android:gravity="center_vertical"
android:text=""
android:textStyle="bold" />
</RelativeLayout>
<View
android:id="#+id/line6"
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:layout_below="#+id/txtlay1"
android:visibility="gone"
android:layout_marginTop="0dp"
android:background="#android:color/darker_gray" />
<RelativeLayout
android:id="#+id/rel4"
android:layout_width="match_parent"
android:layout_height="50dp"
android:visibility="gone"
android:layout_below="#+id/line6"
android:background="#E6E6E6" >
<TextView
android:id="#+id/email_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="#E6E6E6"
android:gravity="center_vertical"
android:text="" />
<TextView
android:id="#+id/email_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:gravity="center_vertical"
android:text="" />
<TextView
android:id="#+id/email_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/email_left"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:text="" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rel5"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_below="#+id/rel4"
android:visibility="gone"
android:layout_marginTop="10dp"
android:background="#E6E6E6" >
<TextView
android:id="#+id/title5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:text="About Us"
android:textColor="#030303"
android:textSize="15dp"
android:textStyle="bold" />
<View
android:id="#+id/line9"
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:layout_below="#+id/title5"
android:layout_marginTop="10dp"
android:background="#android:color/darker_gray" />
</RelativeLayout>
<View
android:id="#+id/line11"
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:layout_below="#+id/rel5"
android:layout_marginTop="10dp"
android:background="#android:color/darker_gray" />
<RelativeLayout
android:id="#+id/rel6"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_below="#+id/line10"
android:visibility="gone"
android:layout_marginTop="10dp"
android:background="#E6E6E6" >
<TextView
android:id="#+id/about_us"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="Website"
android:textColor="#030303"
android:textSize="15dp"
android:textStyle="bold" />
</RelativeLayout>
<View
android:id="#+id/line10"
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:layout_below="#+id/rel6"
android:layout_marginTop="10dp"
android:background="#android:color/darker_gray" />
<TextView
android:id="#+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/rel5"
android:layout_marginLeft="10dp"
android:layout_marginTop="18dp"
android:visibility="gone"
android:text="ffdhjggjhkkghjg"
android:textColor="#030303"
android:textSize="15dp"
android:textStyle="bold" />
<View
android:id="#+id/line10"
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:layout_below="#+id/txt"
android:layout_marginTop="10dp"
android:visibility="gone"
android:background="#android:color/darker_gray" />
<TextView
android:id="#+id/txtweb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/rel6"
android:layout_marginLeft="10dp"
android:layout_marginTop="18dp"
android:text="ffdhjggjhkkghjg"
android:visibility="gone"
android:textColor="#030303"
android:textSize="15dp"
android:textStyle="bold" />
<View
android:id="#+id/line12"
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:layout_below="#+id/txtweb"
android:visibility="gone"
android:layout_marginTop="10dp"
android:background="#android:color/darker_gray" />
</RelativeLayout>
You create Object of category once in pre execute and then you not create new object so the category last value set in the array list everytime you create category object in loop and try it is working
I'm now implementing a custom ListView. When I tried to change the TextView that is located in CustomAdaper.xml from MainActivity. It show NullPointerException. Isn't it possible to do like this . Help me finding it Please . I get so confused .
Below is my MainActivity.java Code :
setContentView(R.layout.activity_main);
txt_Position = (TextView)findViewById(R.id.txtposition);//still ok
txt_memberName = (TextView)findViewById(R.id.txtmemberName);// still ok
LayoutParams params = (LayoutParams) layout_Date.getLayoutParams();
LayoutParams params1 = (LayoutParams) layout_List.getLayoutParams();
LayoutParams params2 = (LayoutParams) layout_Rotation.getLayoutParams();
int screenSize = getResources().getConfiguration().screenLayout &
Configuration.SCREENLAYOUT_SIZE_MASK;
switch(screenSize) {
case Configuration.SCREENLAYOUT_SIZE_LARGE:
Toast.makeText(this, "Large", Toast.LENGTH_LONG).show();
params.height = 100;
params1.height = 330 ;
params2.height = 200;
txt_Position.setTextSize((float)18.0); //locate in CustomAdapter.xml and this is the line logCat Error Pointed .
break;
CustomAdapter.Java
public class CustomAdapter extends BaseAdapter {
private Activity activity;
private ArrayList data;
private static LayoutInflater inflater=null;
public Resources res;
ListModel getList;
int size ;
int i=0;
public CustomAdapter(Activity a, ArrayList d,Resources resLocal, int size) {
activity = a;
data=d;
res = resLocal;
this.size = size;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
if(data.size()<=0)
return 1;
return data.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public static class ViewHolder{
public TextView txt_Name;
public TextView txt_Status;
public TextView txt_Position;
public ImageButton imgbtn_senka;
public ImageButton imgbtn_fuenka;
//public TableRow tblrow_btn;
public RelativeLayout layoutbtn;
public ImageView image;
}
public View getView(final int position, View convertView, ViewGroup parent) {
View vi=convertView;
final ViewHolder holder;
if(convertView==null){
/********** Inflate tabitem.xml file for each row ( Defined below ) ************/
vi = inflater.inflate(R.layout.customadapter, null);
holder=new ViewHolder();
holder.txt_Name = (TextView)vi.findViewById(R.id.txtmemberName);
holder.txt_Status = (TextView)vi.findViewById(R.id.txtmemberStatus);
holder.image = (ImageView)vi.findViewById(R.id.imgPlayer);
holder.imgbtn_fuenka = (ImageButton) vi.findViewById(R.id.btnfusenka);
holder.imgbtn_senka = (ImageButton) vi.findViewById(R.id.btnsenka);
holder.txt_Position = (TextView)vi.findViewById(R.id.txtposition);
holder.layoutbtn = (RelativeLayout)vi.findViewById(R.id.layoutbutton);
vi.setTag(holder);
}
else
holder=(ViewHolder)vi.getTag();
if(data.size()<=0)
{
holder.txt_Name.setText("No Data");
}
else
{
getList=null;
getList = (ListModel) data.get(position);
if(getList.getMemberStatus() == 3){
holder.txt_Status.setVisibility(View.INVISIBLE);
holder.imgbtn_fuenka.setVisibility(View.VISIBLE);
holder.imgbtn_senka.setVisibility(View.VISIBLE);
if(getList.getEntry() == 1){
holder.imgbtn_senka.setImageResource(R.drawable.sankagray);
holder.imgbtn_senka.setEnabled(false);
}
else if(getList.getEntry() == 0){
holder.imgbtn_fuenka.setImageResource(R.drawable.fusankagray);
holder.imgbtn_fuenka.setEnabled(false);
}
holder.imgbtn_senka.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
String entry = "1";
CustomListViewAndroidExample sct = (CustomListViewAndroidExample)activity;
sct.updateData(position , entry);
holder.imgbtn_senka.setImageResource(R.drawable.sankagray);
holder.imgbtn_senka.setEnabled(false);
holder.imgbtn_fuenka.setEnabled(true);
holder.imgbtn_fuenka.setImageResource(R.drawable.fusanka);
}
});
holder.imgbtn_fuenka.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
String entry = "0";
CustomListViewAndroidExample sct = (CustomListViewAndroidExample)activity;
sct.updateData(position , entry);
holder.imgbtn_fuenka.setImageResource(R.drawable.fusankagray);
holder.imgbtn_fuenka.setEnabled(false);
holder.imgbtn_senka.setEnabled(true);
holder.imgbtn_senka.setImageResource(R.drawable.sanka);
}
});
}
else{
holder.txt_Status.setVisibility(View.VISIBLE);
holder.imgbtn_fuenka.setVisibility(View.INVISIBLE);
holder.imgbtn_senka.setVisibility(View.INVISIBLE);
if(getList.getEntry() == 0){
holder.txt_Status.setText("未確認");
}
else if(getList.getEntry() == 1){
holder.txt_Status.setText("参加");
}
else if(getList.getEntry() == 2){
holder.txt_Status.setText("不参加");
}
else if(getList.getEntry() == 3){
holder.txt_Status.setText("取消");
}
}
holder.txt_Name.setText(getList.getMemberName());
holder.txt_Position.setText(getList.getPosition());
String url="http://10.0.2.2/football365/Photo/"+getList.getImage();
try {
Bitmap bitmap= BitmapFactory.decodeStream((InputStream) new URL(url).getContent());
Bitmap resized = Bitmap.createScaledBitmap(bitmap, 76, 76, false);
holder.image.setImageBitmap(resized);
}
catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// holder.image.setImageResource(res.getIdentifier("http://10.0.2.2/football365/Photo/"+getList.getImage(),null,null));
}
if(size == 1){
holder.txt_Name.setTextSize((float)20.0);
}
return vi;
}
public void changeSize(){
ViewHolder holder = new ViewHolder();
holder.txt_Position.setTextSize((float)18.0);
holder.txt_Name.setTextSize((float)20.0);
}
}
This is CustomAdapter.xml
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:id="#+id/tblrowtotal"
android:layout_marginTop="3dp"
android:layout_marginBottom="3dp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:background="#drawable/blackrow2"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imglin1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="2dp"
android:src="#drawable/liney" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:layout_marginLeft="3dp"
android:id="#+id/imgPlayer"
android:layout_width="60dp"
android:layout_height="70dp"
android:layout_gravity="left|top"
android:layout_marginTop="2dp"
android:scaleType="center"
style="#style/AppBaseTheme"
android:background="#null"
/>
</LinearLayout>
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:paddingTop="0dip" >
<TableRow>
<TextView
android:id="#+id/txtmemberName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginTop="15dp"
android:textColor="#FFFFFF"
android:textSize="13sp" />
</TableRow>
<ImageView
android:id="#+id/imgview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/linex" />
<TableRow android:layout_width="wrap_content" >
<ImageView
android:id="#+id/position"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginTop="10dp"
android:src="#drawable/c_position" />
<TextView
android:id="#+id/txtposition"
android:layout_width="45dp"
android:layout_height="30dp"
android:layout_marginLeft="3dp"
android:layout_marginTop="7dp"
android:textColor="#FFFFFF"
android:textSize="15sp" />
<ImageView
android:id="#+id/img2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:scaleType="center"
android:layout_marginLeft="0dp"
android:src="#drawable/liney" />
<RelativeLayout
android:id="#+id/layoutbutton"
android:layout_width="wrap_content"
android:gravity="right"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/txtmemberStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="2dp"
android:gravity="center_horizontal"
android:textColor="#FFFFFF"
android:textSize="16sp" />
<ImageButton
android:id="#+id/btnfusenka"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:layout_marginRight="3dp"
android:background="#null"
android:focusable="false"
android:src="#drawable/fusanka"/>
<ImageButton
android:id="#+id/btnsenka"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#null"
android:focusable="false"
android:src="#drawable/sanka"
/>
</RelativeLayout>
</TableRow>
<ImageView
android:id="#+id/img3"
android:layout_width="fill_parent"
android:layout_marginLeft="0dp"
android:layout_height="wrap_content"
android:src="#drawable/linex" />
</TableLayout>
</TableRow>
Try this:
txt_Position.setTextSize(TypedValue.COMPLEX_UNIT_DIP, Float.parseFloat(18.0));
TRY THIS
txt_Position.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);