-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
529 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
lab2/app/src/main/java/com/example/mainactivity/custom/CustomAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.example.mainactivity.custom; | ||
|
||
import android.content.Context; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.BaseAdapter; | ||
import android.widget.CheckBox; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
import android.widget.Toast; | ||
|
||
import com.example.mainactivity.R; | ||
|
||
|
||
|
||
class Item{ | ||
TextView text1; | ||
TextView text2; | ||
ImageView image1; | ||
CheckBox checkbox1; | ||
} | ||
|
||
public class CustomAdapter extends BaseAdapter { | ||
String[] titles; | ||
String[] subtitles; | ||
boolean[] checked; | ||
LayoutInflater inf=null; | ||
Context context; | ||
|
||
|
||
public CustomAdapter(String[] titles, String[] subtitles,Context ctx){ | ||
super(); | ||
this.titles=titles; | ||
this.subtitles=subtitles; | ||
this.checked=new boolean[titles.length]; | ||
inf=(LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE); | ||
context=ctx; | ||
|
||
|
||
} | ||
@Override | ||
public int getCount() { | ||
return titles.length; | ||
} | ||
|
||
@Override | ||
public Object getItem(int position) { | ||
return position; | ||
} | ||
|
||
@Override | ||
public long getItemId(int position) { | ||
return position; | ||
} | ||
|
||
@Override | ||
public View getView(int position, View view, ViewGroup parent) { | ||
Item item1 =new Item(); | ||
if(view==null){ | ||
|
||
view=inf.inflate(R.layout.list_row,null); | ||
item1.checkbox1=(CheckBox) view.findViewById((R.id.myCheckBox)); | ||
item1.text1=(TextView)view.findViewById(R.id.row_tv1); | ||
item1.text2=(TextView)view.findViewById(R.id.row_tv2); | ||
item1.image1=(ImageView)view.findViewById(R.id.row_image); | ||
view.setTag(item1); | ||
|
||
}else{ | ||
item1=(Item)view.getTag(); | ||
|
||
} | ||
item1.text1.setText((titles[position])); | ||
item1.text2.setText((subtitles[position])); | ||
item1.checkbox1.setChecked(checked[position]); | ||
item1.checkbox1.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
if(((CheckBox)v ).isChecked()){ | ||
checked[position]=true; | ||
}else{ | ||
checked[position]=false; | ||
} | ||
Toast.makeText(context.getApplicationContext(), "Checkbox clicked", Toast.LENGTH_SHORT).show(); | ||
|
||
} | ||
}); | ||
return view; | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
lab2/app/src/main/java/com/example/mainactivity/custom/GridImageAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.example.mainactivity.custom; | ||
|
||
import android.content.Context; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.BaseAdapter; | ||
import android.widget.GridView; | ||
import android.widget.ImageView; | ||
|
||
import com.example.mainactivity.R; | ||
|
||
public class GridImageAdapter extends BaseAdapter { | ||
private Context context; | ||
|
||
public Integer[] images={ | ||
R.drawable.img1,R.drawable.img2,R.drawable.img3, | ||
R.drawable.img2,R.drawable.img3,R.drawable.img1, | ||
R.drawable.img3,R.drawable.img1,R.drawable.img2, | ||
}; | ||
public GridImageAdapter(Context c){ | ||
context=c; | ||
} | ||
@Override | ||
public int getCount() { | ||
return images.length; | ||
} | ||
|
||
@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) { | ||
ImageView view; | ||
if(convertView==null){ | ||
view=new ImageView(context); | ||
view.setLayoutParams(new ViewGroup.LayoutParams(200,200)); | ||
view.setScaleType(ImageView.ScaleType.CENTER_CROP); | ||
view.setPadding(8,8,8,8); | ||
//create new image | ||
}else{ | ||
view=(ImageView) convertView; | ||
|
||
} | ||
view.setImageResource(images[position]); | ||
return view; | ||
|
||
|
||
|
||
} | ||
} |
Oops, something went wrong.