Skip to content

Commit

Permalink
lab2
Browse files Browse the repository at this point in the history
  • Loading branch information
mskaa3 committed Oct 24, 2021
1 parent bd8474e commit f3740d9
Show file tree
Hide file tree
Showing 19 changed files with 529 additions and 17 deletions.
1 change: 1 addition & 0 deletions lab2/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions lab2/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions lab2/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mainactivity" >
package="com.example.mainactivity">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MainActivity" >
android:theme="@style/Theme.MainActivity">
<activity
android:name=".customActivity"
android:exported="true" />
<activity
android:name=".grid"
android:exported="true" />
Expand All @@ -20,7 +23,7 @@
android:exported="true" />
<activity
android:name=".MainActivity"
android:exported="true" >
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
29 changes: 22 additions & 7 deletions lab2/app/src/main/java/com/example/mainactivity/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.example.mainactivity;

import android.content.Intent;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

Expand All @@ -21,7 +23,7 @@ protected void onCreate(Bundle savedInstanceState) {

public void openSimpleList(View view){
Intent intent1=new Intent();
intent1.setClass(getApplicationContext(),SimpleList.class);
intent1.setClass(this,SimpleList.class);
startActivity(intent1);

}
Expand All @@ -30,20 +32,33 @@ public void openSimpleList(View view){
public void openMultipleChoiceList(View view){
Intent intent1=new Intent();
intent1.setClass(getApplicationContext(),MultipleChoiceList.class);
// startActivityForResult(intent1,0);
startActivity(intent1);

}

public void openGrid(View view){
Intent intent1=new Intent();
intent1.setClass(getApplicationContext(),grid.class);
intent1.putExtra("arg1","Value1");
intent1.putExtra("arg2",2);

startActivity(intent1);

}
public void openCustom(View view){
Intent intent1=new Intent();
intent1.setClass(getApplicationContext(),customActivity.class);
startActivity(intent1);

}
// public void custom(View view){
// Intent intent1=new Intent();
// intent1.setClass(getApplicationContext(),grid.class);
// startActivity(intent1);
//
// @Override
// protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data){
// super.onActivityResult(requestCode,resultCode,data);
// if(resultCode==0){
// Toast.makeText(this,"nothing selected", Toast.LENGTH_SHORT).show();
// }else{
// Toast.makeText(this, data.getStringExtra("Result"), Toast.LENGTH_SHORT).show();
// }
// }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,63 @@

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.SparseBooleanArray;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class MultipleChoiceList extends AppCompatActivity {
public class MultipleChoiceList extends AppCompatActivity implements AdapterView.OnItemClickListener {
String[] inMyMultipleList = {
"item1",
"item2",
"item3",
"item4",
"item5",
"item6",
"item7",
"item8",
"item9",
"item10",
"item11",
"item12",
"item13",
"item14",
"item15",

};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_multiple_choice_list);
// setResult(0);
ArrayAdapter<String> array = new ArrayAdapter<>(this, android.R.layout.simple_list_item_multiple_choice);
array.addAll(inMyMultipleList);
ListView list_view = findViewById(R.id.myMultipleList);
list_view.setAdapter(array);
list_view.setOnItemClickListener(this);
}

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String info = "";
SparseBooleanArray checked = ((ListView) findViewById(R.id.myMultipleList)).getCheckedItemPositions();
for (int i = 0; i < checked.size(); i++) {
if (checked.valueAt(i)) {
int index = checked.keyAt(i);
info = info + " " + String.valueOf(index + 1) + ",";

}
// getIntent().putExtra("RESULT", info);
// setResult(1, getIntent());
Toast.makeText(this, "You have selected: " + info, Toast.LENGTH_SHORT).show();
}
}

@Override
public void onPointerCaptureChanged( boolean hasCapture){

}
}
}
20 changes: 19 additions & 1 deletion lab2/app/src/main/java/com/example/mainactivity/SimpleList.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class SimpleList extends AppCompatActivity {
public class SimpleList extends AppCompatActivity implements AdapterView.OnItemClickListener{
String[] inMyList={
"item1",
"item2",
Expand All @@ -17,6 +20,12 @@ public class SimpleList extends AppCompatActivity {
"item7",
"item8",
"item9",
"item10",
"item11",
"item12",
"item13",
"item14",
"item15",

};
@Override
Expand All @@ -28,6 +37,15 @@ protected void onCreate(Bundle savedInstanceState) {
array.addAll(inMyList);
ListView list_view=findViewById(R.id.mySimpleList);
list_view.setAdapter(array);
list_view.setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView adapterView, View view, int x, long z){
Toast.makeText(this,inMyList[x],Toast.LENGTH_SHORT).show();
}

@Override
public void onPointerCaptureChanged(boolean hasCapture) {

}
}
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;
}
}
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;



}
}
Loading

0 comments on commit f3740d9

Please sign in to comment.