CopyPastor

Detecting plagiarism made easy.

Score: 1.7432115077972412; Reported for: String similarity, Exact paragraph match Open both answers

Possible Plagiarism

Reposted on 2016-10-14
by Ganesh Pokale

Original Post

Original - Posted on 2016-10-14
by Ganesh Pokale



            
Present in both answers; Present only in the new answer; Present only in the old answer;

Add new Class `CustomChilds`
package stack.buy.com.stackdemos;
/** * Created by Desktop - Ganesh on 10/14/2016. */ public class CustomChilds { String Quntity; String Unit; String Note; String GroupName;
public String getQuntity() { return Quntity; }
public void setQuntity(String quntity) { Quntity = quntity; }
public String getUnit() { return Unit; }
public void setUnit(String unit) { Unit = unit; }
public String getNote() { return Note; }
public void setNote(String note) { Note = note; }
public String getGroupName() { return GroupName; }
public void setGroupName(String groupName) { GroupName = groupName; }
public CustomChilds(String quntity, String unit, String note, String groupName) { Quntity = quntity; Unit = unit; Note = note; GroupName = groupName; }
public CustomChilds() { } }




Adapter:
public class ExpandableListAdapter extends BaseExpandableListAdapter {
private Context _context; private List<String> _listDataHeader; // header titles // child data in format of header title, child title private HashMap<String, List<CustomChilds>> _listDataChild; // private final HashMap<String, String, String> mCheckedItems; String cat, item, quty, units, notes;
ArrayList<String> ss = new ArrayList<>();
public ExpandableListAdapter(Context context, List<String> listDataHeader, HashMap<String, List<CustomChilds>> listChildData) { this._context = context; this._listDataHeader = listDataHeader; this._listDataChild = listChildData; } @Override public CustomChilds getChild( int groupPosition, int childPosititon){ return this._listDataChild.get(this._listDataHeader.get(groupPosition)) .get(childPosititon); }
@Override public long getChildId ( int groupPosition, int childPosition){ return childPosition; }
@Override public View getChildView ( final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent){
final CustomChilds childText =getChild(groupPosition, childPosition); final ViewHolder holder;
View row = convertView; if (row == null) { LayoutInflater inflater = (LayoutInflater) this._context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); row = inflater.inflate(R.layout.list_item, parent, false); holder = new ViewHolder(); holder.mm = (LinearLayout) row.findViewById(R.id.entries); holder.qty = (EditText) row.findViewById(R.id.qty1); holder.note = (EditText) row.findViewById(R.id.note); holder.unit = (Spinner) row.findViewById(R.id.unit); holder.cb = (CheckBox) row.findViewById(R.id.cb); holder.txtListChild = (TextView) row .findViewById(R.id.lblListItem); row.setTag(holder); }
else { // view already exists, get the holder instance from the view holder = (ViewHolder) row.getTag(); }
List<CustomChilds> temp = _listDataChild.get(this._listDataHeader.get(groupPosition)); temp.set(childPosition,new CustomChilds(holder.qty.getText().toString(),holder.unit.getSelectedItem().toString(),holder.note.getText().toString(),childText.GroupName));
final int grp = groupPosition;
holder.cb.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
final CheckBox cb = (CheckBox) v;
if (cb.isChecked()) { holder.mm.setVisibility(View.VISIBLE); } else { holder.mm.setVisibility(View.GONE);
} System.out.println(ss); } });
holder.txtListChild.setText(childText.getGroupName());
return row; }


@Override public int getChildrenCount(int groupPosition) { return this._listDataChild.get(this._listDataHeader.get(groupPosition)) .size(); }
@Override public Object getGroup(int groupPosition) { return this._listDataHeader.get(groupPosition); }
@Override public int getGroupCount() { return this._listDataHeader.size(); }
@Override public long getGroupId(int groupPosition) { return groupPosition; }
@Override public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { String headerTitle = (String) getGroup(groupPosition); if (convertView == null) { LayoutInflater infalInflater = (LayoutInflater) this._context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = infalInflater.inflate(R.layout.list_group, null); } TextView lblListHeader = (TextView) convertView .findViewById(R.id.lblListHeader);
lblListHeader.setTypeface(null, Typeface.BOLD); lblListHeader.setText(headerTitle);
return convertView; }
@Override public boolean hasStableIds() { return false; }
@Override public boolean isChildSelectable(int groupPosition, int childPosition) { return true; }


// somewhere else in your class definition static class ViewHolder { EditText qty; EditText note; Spinner unit; LinearLayout mm; CheckBox cb; TextView txtListChild; } }


MainActivity
public class MainActivity extends AppCompatActivity {
ExpandableListAdapter listAdapter; ExpandableListView expListView; List<String> listDataHeader; HashMap<String, List<CustomChilds>> listDataChild;
Button save; Button cancel;
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
save = (Button) findViewById(R.id.save);

listAdapter = new ExpandableListAdapter(getApplicationContext(), listDataHeader, listDataChild);


expListView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
save.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { System.out.println("Save clicked"); for(int i = 0; i < listAdapter.getGroupCount();i++) { for (int k = 0; k < listAdapter.getChildrenCount(i); k++) {

CustomChilds child = listAdapter.getChild(i, k); String unit=child.getUnit(); String note=child.getNote(); String qut=child.getQuntity();
System.out.println("For i="+i+" and k="+k+" string value is="+child.getNote()); } } } });


}


private void prepareListData() { listDataHeader = new ArrayList<String>(); listDataChild = new HashMap<String, List<CustomChilds>>(); listDataHeader.add("Nokia"); listDataHeader.add("Apple"); listDataHeader.add("Samsung");
List<CustomChilds> nokia = new ArrayList<CustomChilds>(); nokia.add(new CustomChilds("","","","Nokia1")); nokia.add(new CustomChilds("","","","Nokia2"));

List<CustomChilds> apple = new ArrayList<CustomChilds>(); apple.add(new CustomChilds("","","","Apple1")); apple.add(new CustomChilds("","","","Apple2"));


List<CustomChilds> samsung = new ArrayList<CustomChilds>(); samsung.add(new CustomChilds("","","","Samsung1")); samsung.add(new CustomChilds("","","","Samsung2"));
listDataChild.put(listDataHeader.get(0), nokia); // Header, Child data listDataChild.put(listDataHeader.get(1), apple); listDataChild.put(listDataHeader.get(2), samsung); } }


Get Unit, Quantity and Note onClick
save.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { System.out.println("Save clicked"); for(int i = 0; i < listAdapter.getGroupCount();i++) { for (int k = 0; k < listAdapter.getChildrenCount(i); k++) {

CustomChilds child = listAdapter.getChild(i, k); String unit=child.getUnit(); String note=child.getNote(); String qut=child.getQuntity();
System.out.println("For i="+i+" and k="+k+" string value is="+child.getNote()); } } } });
Try this
save.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { System.out.println("Save clicked"); for(int i = 0; i < listAdapter.getGroupCount();i++) { String group = listAdapter.getGroup(i).toString(); for (int k = 0; k < listAdapter.getChildrenCount(i); k++) {

String child = listAdapter.getChild(i, k).toString();;
System.out.println("For i="+i+" and k="+k+" string value is="+child); } } } });


Stack trace:
10-14 16:19:38.877 20206-20206/stack.buy.com.stackdemos I/System.out: For i=0 and k=0 string value is=Nokia1 10-14 16:19:41.395 20206-20206/stack.buy.com.stackdemos I/System.out: For i=0 and k=1 string value is=Nokia2 10-14 16:19:45.015 20206-20206/stack.buy.com.stackdemos I/System.out: For i i=1 and k=0 string value is=Apple1 10-14 16:19:47.663 20206-20206/stack.buy.com.stackdemos I/System.out: For i=1 and k=1 string value is=Apple2 10-14 16:19:50.968 20206-20206/stack.buy.com.stackdemos I/System.out: For i=2 and k=0 string value is=Samsung1 10-14 16:19:51.957 20206-20206/stack.buy.com.stackdemos I/System.out: For i=2 and k=1 string value is=Samsung2

Also for custom views `ViewHolder` strategy is good


public class ExpandableListAdapter extends BaseExpandableListAdapter {
private Context _context; private List<String> _listDataHeader; // header titles // child data in format of header title, child title private HashMap<String, List<String>> _listDataChild; // private final HashMap<String, String, String> mCheckedItems; String cat, item, quty, units, notes;
ArrayList<String> ss = new ArrayList<>();
public ExpandableListAdapter(Context context, List<String> listDataHeader, HashMap<String, List<String>> listChildData) { this._context = context; this._listDataHeader = listDataHeader; this._listDataChild = listChildData; } @Override public Object getChild( int groupPosition, int childPosititon){ return this._listDataChild.get(this._listDataHeader.get(groupPosition)) .get(childPosititon); }
@Override public long getChildId ( int groupPosition, int childPosition){ return childPosition; }
@Override public View getChildView ( final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent){
final String childText = (String) getChild(groupPosition, childPosition); final ViewHolder holder;
View row = convertView; if (row == null) { LayoutInflater inflater = (LayoutInflater) this._context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); row = inflater.inflate(R.layout.list_item, parent, false); holder = new ViewHolder(); holder.mm = (LinearLayout) row.findViewById(R.id.entries); holder.qty = (EditText) row.findViewById(R.id.qty1); holder.note = (EditText) row.findViewById(R.id.note); holder.unit = (Spinner) row.findViewById(R.id.unit); holder.cb = (CheckBox) row.findViewById(R.id.cb); holder.txtListChild = (TextView) row .findViewById(R.id.lblListItem); row.setTag(holder); }
else { // view already exists, get the holder instance from the view holder = (ViewHolder) row.getTag(); }


final int grp = groupPosition;
holder.cb.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
final CheckBox cb = (CheckBox) v;
if (cb.isChecked()) { holder.mm.setVisibility(View.VISIBLE); } else { holder.mm.setVisibility(View.GONE);
} System.out.println(ss); } });
holder.txtListChild.setText(childText);
return row; }
/* public String recollect(int grp, int ch) { cat = getGroup(grp).toString(); item = getChild(grp, ch).toString(); quty = qty.getText().toString(); units = unit.getSelectedItem().toString(); notes = note.getText().toString();
System.out.println("cat=" + cat + "; item=" + item + "; qty=" + quty + "; unit=" + units + "; note=" + notes); return cat + ";" + item + ";" + quty + ";" + units + ";" + notes + "_"; }*/
@Override public int getChildrenCount(int groupPosition) { return this._listDataChild.get(this._listDataHeader.get(groupPosition)) .size(); }
@Override public Object getGroup(int groupPosition) { return this._listDataHeader.get(groupPosition); }
@Override public int getGroupCount() { return this._listDataHeader.size(); }
@Override public long getGroupId(int groupPosition) { return groupPosition; }
@Override public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { String headerTitle = (String) getGroup(groupPosition); if (convertView == null) { LayoutInflater infalInflater = (LayoutInflater) this._context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = infalInflater.inflate(R.layout.list_group, null); } TextView lblListHeader = (TextView) convertView .findViewById(R.id.lblListHeader);
lblListHeader.setTypeface(null, Typeface.BOLD); lblListHeader.setText(headerTitle);
return convertView; }
@Override public boolean hasStableIds() { return false; }
@Override public boolean isChildSelectable(int groupPosition, int childPosition) { return true; }


// somewhere else in your class definition static class ViewHolder { EditText qty; EditText note; Spinner unit; LinearLayout mm; CheckBox cb; TextView txtListChild; } }

Like, onChildClick if you want current view then you can access like this:
EditText note= (EditText) v.findViewById(R.id.note); String value = tv.getText().toString();

        
Present in both answers; Present only in the new answer; Present only in the old answer;