NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package com.uts.uts;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import java.lang.reflect.Array;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Locale;

public class MainActivity extends AppCompatActivity implements RecycleAdapter.ItemClickListener {

private RecycleAdapter rAdapter;
private ArrayList<Integer> gambarbrg;
private ArrayList<Anggrek> Anggrek;
private float price;
private int gbr[] = {R.drawable.anggrek1, R.drawable.anggrek2, R.drawable.anggrek3, R.drawable.anggrek4};
private ImageView gambar;
private int tot = 0, bayar;
private TextView totbyr;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
totbyr = (TextView) findViewById(R.id.txttotbyr);
RecyclerView rView = (RecyclerView) findViewById(R.id.my_recycler_view);
rView.setHasFixedSize(true);
GridLayoutManager k = new GridLayoutManager(this, 2);
rView.setLayoutManager(k);
gambarbrg = new ArrayList<>();
ambdata();
item();
totbyr.setText("Rp. "+ Double.toString(price));
rAdapter = new RecycleAdapter(Anggrek,gambarbrg,this,this);
rView.setAdapter(rAdapter);
rAdapter.setClickListener(this);


}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}


public void sms() {
Uri sms_uri = Uri.parse("smsto:+6281225075776");
Intent sms = new Intent(Intent.ACTION_SENDTO, sms_uri);
sms.putExtra("SMS", "SMS center");
startActivity(sms);
}

public void call() {
Uri call_uri = Uri.parse("tel: +6281225075776");
Intent call = new Intent(Intent.ACTION_DIAL, call_uri);
call.putExtra("Call", "Call center");
startActivity(call);
}

public void Lokasi() {
String loc = "Kampung Anggrek Sodong Semarang";
Uri addressUri = Uri.parse("geo:-7.079684,110.3273094?q=" + loc);
Intent map = new Intent(Intent.ACTION_VIEW, addressUri);
startActivity(map);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

int id = item.getItemId();

if (id == R.id.call) {
call();
}
if (id == R.id.sms) {
sms();
}
if (id == R.id.map) {
Lokasi();
}


return super.onOptionsItemSelected(item);
}

public void ambdata() {
Anggrek = new ArrayList<>();
Anggrek.add(new Anggrek("Anggrek Ascocentrum Miniatum",25000));
Anggrek.add(new Anggrek("Anggrek Doritis",79000));
Anggrek.add(new Anggrek("Anggrek Macan",35000));
Anggrek.add(new Anggrek("Anggrek Vanda",150000));
}
public void item(){
for (int w=0; w<gbr.length; w++){
gambarbrg.add(gbr[w]);
}
}

public void onClick(View view, int position) {
Anggrek = new ArrayList<Anggrek>();
double anggrekPrice = Anggrek.get(position).getHarga();
switch (view.getId()){
case R.id.img_card :
price = price+(float)anggrekPrice;
DecimalFormat decimalFormat = new DecimalFormat("#,##0.00");
totbyr.setText(decimalFormat.format(price));
return;
default:
Intent desc = new Intent(getApplicationContext(),Deskripsi.class);
desc.putExtra("judul", Anggrek.get(position).getJudul());
desc.putExtra("harga", String.valueOf(Anggrek.get(position).getHarga()));
desc.putExtra("gambar", gambarbrg.get(position));
return;
}

}
}


=====================================================================



package com.uts.uts;


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;

import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Locale;

public class RecycleAdapter extends RecyclerView.Adapter<RecycleAdapter.RecycleViewHolder> {
public interface ItemClickListener {
void onClick(View view, int position);
}//tambahan
private ArrayList<Anggrek> Anggrek;
private ArrayList<Integer> gbrList;
private Activity activity;
private Context konteks;
private ItemClickListener clickListener;


public RecycleAdapter( ArrayList<Anggrek> Anggrek,ArrayList<Integer> gbrList,Activity activity,Context konteks) { //tambahan
this.gbrList=gbrList; //tambahan
this.konteks=konteks;
this.Anggrek=Anggrek;
this.activity=activity;
}

@Override
public RecycleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
View view = layoutInflater.inflate(R.layout.item_list, parent, false);
return new RecycleViewHolder(view);
}

@Override
public void onBindViewHolder(RecycleViewHolder holder, int position) {
holder.txtjdl.setText(Anggrek.get(position).getJudul());
holder.txthrg.setText("Rp. "+String.valueOf(Anggrek.get(position).getHarga()));
holder.imgGbr.setImageResource(gbrList.get(position)); //tambahan
}

@Override
public int getItemCount() {
return (gbrList != null) ? gbrList.size() : 0;
}

public void setClickListener(ItemClickListener clickListener) {
this.clickListener = clickListener;
}

public class RecycleViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
private TextView txtjdl, txthrg,txttotbyr;
private ImageView imgGbr; //tambahan
private LinearLayout view;
public String KEY_JUDUL="judul";
public String KEY_GAMBAR="gambar";
public String KEY_HARGA="harga";
public RecycleViewHolder(View itemView) {
super(itemView);
konteks = itemView.getContext();
txtjdl = (TextView) itemView.findViewById(R.id.Judul);
txthrg = (TextView) itemView.findViewById(R.id.Harga);
txttotbyr = (TextView) itemView.findViewById(R.id.txttotbyr);
imgGbr= itemView.findViewById(R.id.img_card); //tambahan
view = itemView.findViewById(R.id.View);
itemView.setTag(itemView);
itemView.setOnClickListener(this);
imgGbr.setOnClickListener(this);
txtjdl.setOnClickListener(this);
}
public void onClick(View view) {
if(clickListener != null) clickListener.onClick(view, getAdapterPosition());
}
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.