In First java file
my_listview.java
package ListView.app;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class my_listview extends Activity {
ListView itemList = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listview2);
// TODO Auto-generated method stub
itemList = (ListView) findViewById(R.id.itemList);
itemList.setAdapter(new EfficientAdapter(this));
}
String[] Qitems = {
"Q1:What are the advantages of Object Oriented Programming Languages (OOPL)?",
"Q2:How do you express an ‘is a’ relationship and a ‘has a’ relationship or explain inheritance and composition? What is the difference between composition and aggregation?",
"Q3:What do you mean by polymorphism, inheritance, encapsulation, and dynamic binding?",
"Q4:What is the difference between an abstract class and an interface and when should you use them?",
"Q5:How would you communicate between applets and servlets?",
"Q6:Why use LDAP when you can do the same with relational database (RDBMS)?",
"Q7:Explain the RMI architecture?",
"Q8:What is a remote object? Why should we extend UnicastRemoteObject?",
"Q9:How will you pass parameters in RMI?",
"Q10:What is the difference between final, finally and finalize() in Java?",
"Q11:Why use LDAP when you can do the same with relational database (RDBMS)?",
"Q12:Explain the RMI architecture?",
"Q13:What is a remote object? Why should we extend UnicastRemoteObject?",
"Q14:How will you pass parameters in RMI?",
"Q15:What is the difference between final, finally and finalize() in Java?"};
String[] Aitems = { "The Object Oriented Programming Languages directly represent the real life objects like Car,",
"The ‘is a’ relationship is expressed with inheritance and ‘has a’ relationship is expressed with ",
"Polymorphism – means the ability of a single variable of a given type to be used to reference objects",
"In design, you want the base class to present only an interface for its derived classes. This means, ",
"We can use the java.net.URLConnection and java.net.URL classes to open a standard HTTP connection and",
"Java Remote Method Invocation (RMI) provides a way for a Java program on one machine to communicate ",
"A remote object is one whose methods can be invoked from another JVM (i.e. another process). A remote",
"The client process initiates the invocation of the remote method by calling the method on the stub.",
"final - constant declaration. Refer Q31 in Java section. finally - handles exception. The finally block ",
"Java Remote Method Invocation (RMI) provides a way for a Java program on one machine to communicate with",
"A remote object is one whose methods can be invoked from another JVM (i.e. another process). A remote",
"The client process initiates the invocation of the remote method by calling the method on the stub.",
"final - constant declaration. Refer Q31 in Java section. finally - handles exception. The finally block",
"Java Remote Method Invocation (RMI) provides a way for a Java program on one machine to communicate",
"In design, you want the base class to present only an interface for its derived classes. "};
public class EfficientAdapter extends BaseAdapter {
private LayoutInflater mInflater;
public Context ctxt;
public EfficientAdapter(Context context) {
mInflater = LayoutInflater.from(context);
this.ctxt = context;
}
public int getCount() {
return Qitems.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.custom_listview, null);
holder = new ViewHolder();
holder.titletxt = (TextView) convertView.findViewById(R.id.titletxt);
holder.ratingtxt = (TextView) convertView.findViewById(R.id.ratingtxt);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.ratingtxt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(my_listview.this,page2.class);
i.putExtra("Q",Qitems[position]);
i.putExtra("A",Aitems[position]);
startActivity(i);
}
});
holder.titletxt.setText(Qitems[position]);
holder.ratingtxt.setText("Answer");
return convertView;
}
class ViewHolder {
TextView titletxt;
TextView ratingtxt;
}
}
}
my_listview.java
package ListView.app;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class my_listview extends Activity {
ListView itemList = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listview2);
// TODO Auto-generated method stub
itemList = (ListView) findViewById(R.id.itemList);
itemList.setAdapter(new EfficientAdapter(this));
}
String[] Qitems = {
"Q1:What are the advantages of Object Oriented Programming Languages (OOPL)?",
"Q2:How do you express an ‘is a’ relationship and a ‘has a’ relationship or explain inheritance and composition? What is the difference between composition and aggregation?",
"Q3:What do you mean by polymorphism, inheritance, encapsulation, and dynamic binding?",
"Q4:What is the difference between an abstract class and an interface and when should you use them?",
"Q5:How would you communicate between applets and servlets?",
"Q6:Why use LDAP when you can do the same with relational database (RDBMS)?",
"Q7:Explain the RMI architecture?",
"Q8:What is a remote object? Why should we extend UnicastRemoteObject?",
"Q9:How will you pass parameters in RMI?",
"Q10:What is the difference between final, finally and finalize() in Java?",
"Q11:Why use LDAP when you can do the same with relational database (RDBMS)?",
"Q12:Explain the RMI architecture?",
"Q13:What is a remote object? Why should we extend UnicastRemoteObject?",
"Q14:How will you pass parameters in RMI?",
"Q15:What is the difference between final, finally and finalize() in Java?"};
String[] Aitems = { "The Object Oriented Programming Languages directly represent the real life objects like Car,",
"The ‘is a’ relationship is expressed with inheritance and ‘has a’ relationship is expressed with ",
"Polymorphism – means the ability of a single variable of a given type to be used to reference objects",
"In design, you want the base class to present only an interface for its derived classes. This means, ",
"We can use the java.net.URLConnection and java.net.URL classes to open a standard HTTP connection and",
"Java Remote Method Invocation (RMI) provides a way for a Java program on one machine to communicate ",
"A remote object is one whose methods can be invoked from another JVM (i.e. another process). A remote",
"The client process initiates the invocation of the remote method by calling the method on the stub.",
"final - constant declaration. Refer Q31 in Java section. finally - handles exception. The finally block ",
"Java Remote Method Invocation (RMI) provides a way for a Java program on one machine to communicate with",
"A remote object is one whose methods can be invoked from another JVM (i.e. another process). A remote",
"The client process initiates the invocation of the remote method by calling the method on the stub.",
"final - constant declaration. Refer Q31 in Java section. finally - handles exception. The finally block",
"Java Remote Method Invocation (RMI) provides a way for a Java program on one machine to communicate",
"In design, you want the base class to present only an interface for its derived classes. "};
public class EfficientAdapter extends BaseAdapter {
private LayoutInflater mInflater;
public Context ctxt;
public EfficientAdapter(Context context) {
mInflater = LayoutInflater.from(context);
this.ctxt = context;
}
public int getCount() {
return Qitems.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.custom_listview, null);
holder = new ViewHolder();
holder.titletxt = (TextView) convertView.findViewById(R.id.titletxt);
holder.ratingtxt = (TextView) convertView.findViewById(R.id.ratingtxt);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.ratingtxt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(my_listview.this,page2.class);
i.putExtra("Q",Qitems[position]);
i.putExtra("A",Aitems[position]);
startActivity(i);
}
});
holder.titletxt.setText(Qitems[position]);
holder.ratingtxt.setText("Answer");
return convertView;
}
class ViewHolder {
TextView titletxt;
TextView ratingtxt;
}
}
}
In Second java file
page2.java
package ListView.app;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class page2 extends Activity {
TextView tvQ = null;
TextView tvA = null;
Button btnback = null;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.page2);
Bundle bunble = getIntent().getExtras();
tvQ = (TextView)findViewById(R.id.TxtViewQuestion);
tvA = (TextView)findViewById(R.id.TxtViewAnswer);
btnback = (Button)findViewById(R.id.back);
tvQ.setText(bunble.getString("Q"));
tvA.setText(bunble.getString("A"));
btnback.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
onBackPressed();
}
});
}
}
In first xml file
custom_listview.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:id="@+id/RelativeLayout1"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<TextView
android:id="@+id/titletxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10px"
android:textColor="#ffffff"
android:textSize="18sp"
android:text="fasdsadsad"
android:textStyle="bold">
</TextView>
<TextView
android:id="@+id/ratingtxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10px"
android:textColor="#ffffff"
android:text="123"
android:layout_below="@+id/titletxt"
android:textSize="10sp">
</TextView>
</RelativeLayout>
</LinearLayout>
In second xml file
listview2.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/ImageView1"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:background="@drawable/icon">
</ImageView>
<ListView
android:layout_below="@+id/ImageView1"
android:id="@+id/itemList"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:background="#20000000">
</ListView>
</RelativeLayout>
In third xml file
page2.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:orientation="vertical"
>
<Button
android:text="Back"
android:id="@+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
</Button>
<TextView
android:id="@+id/TxtViewQuestion"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text=""
/>
<TextView
android:id="@+id/TxtViewAnswer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#0000A0"
android:text=""
/>
</LinearLayout>
No comments:
Post a Comment