我正面临一个问题,如下所述。
编译此代码时,错误将显示为" 输入事件处理错误"。
我将共享代码但代码相同,当我在另一个活动中运行时,代码会正确执行并且不会显示错误。
请告诉我这有什么问题?
Programs.java
package net.meask.prestonstudent;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.ShareActionProvider;
import android.widget.Toast;
import net.meask.prestonstudent.R;
import net.meask.prestonstudent.CustomProgramsListAdapter;
public class Programs extends ListActivity {
private ListView list;
String[] itemname ={
"Bachelor of Business (BBA)",
"Master of Business (MBA)",
"Executive Master (EMBA)",
"Master of Science (MS) / MBA",
"Bachelor of Science (BS)",
"Master of Science (MS)",
"Executive Master of Science (MS)",
"M.Sc Electronics",
"M.Sc Telecommunication",
"M.Sc Mathematics",
"B-Tech (Pass)",
"B-Tech (Honors)",
"M-Tech",
"M.Sc Economics",
"M.Sc Applied Psychology",
"M.Sc International Relations",
"M.Sc International Diplomacy",
"B.Ed (Education)",
"M.Ed (Education)",
"M.A (Education)",
};
Integer[] imgid={
R.drawable.ic_graduation_pro,
R.drawable.ic_graduation_pro,
R.drawable.ic_graduation_pro,
R.drawable.ic_graduation_pro,
R.drawable.ic_graduation_pro,
R.drawable.ic_graduation_pro,
R.drawable.ic_graduation_pro,
R.drawable.ic_graduation_pro,
R.drawable.ic_graduation_pro,
R.drawable.ic_graduation_pro,
R.drawable.ic_graduation_pro,
R.drawable.ic_graduation_pro,
R.drawable.ic_graduation_pro,
R.drawable.ic_graduation_pro,
R.drawable.ic_graduation_pro,
R.drawable.ic_graduation_pro,
R.drawable.ic_graduation_pro,
R.drawable.ic_graduation_pro,
R.drawable.ic_graduation_pro,
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
list = (ListView) findViewById(R.id.listview);
CustomProgramsListAdapter adapter=new CustomProgramsListAdapter(this, itemname, imgid);
setListAdapter(adapter);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// get selected items
String selectedValue = (String) getListAdapter().getItem(position);
if(position == 0)
{
AlertDialog.Builder alert = new AlertDialog.Builder(Programs.this);
// alert.setIcon(R.drawable.ic_alert_icon);
alert.setTitle("Bachelor of Business Administration (BBA)");
alert.setMessage("1- High School graduation (12 years of school education)" + "\n"
+ "2- Higher Secondary School Certificate or Intermediate Certificate in science, arts, or commerce (FA, FSc, I.Com)" + "\n"
+ "3- Diploma in Commerce with Certificate in Commerce (C.Com+D.Com)" + "\n"
+ "4- GCE O’Levels (minimum eight subjects) Plus A’Levels (min 3 subjects)" + "\n"
+ "5- International Baccalaureate" + "\n" + "\n"
+ "In addition to the minimum qualification, candidates are required to qualify a written test and an interview for admission to BBA Program."
);
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alert.create();
alert.show();
}
else if(position == 1)
{
AlertDialog.Builder alert = new AlertDialog.Builder(Programs.this);
// alert.setIcon(R.drawable.ic_alert_icon);
alert.setTitle("Master of Business Administration (MBA)");
alert.setMessage("1- BBA, BA, BSc, B.Com, BSc Engg., BSc Agri., BSc Comp Sc., L.L.B., or equivalent bachelor’s degree qualification." + "\n" + "\n"
+ "All elective courses are determined by the University at the beginning of each semester and are offered to the entire class. The students are required to take the complete block of optional courses offered by the University in any semester." + "\n" + "\n"
+ "In addition to the requirement for earned credits, a cumulative grade-point-average (GPA) of minimum 2.2 for all masters degree programs on a scale of 0.0 - 4.0 must be attained. In addition to the minimum qualification, a candidate must qualify a Written Test and an Interview for admission to the MBA Program." + "\n"
);
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alert.create();
alert.show();
}
else if(position == 2)
{
AlertDialog.Builder alert = new AlertDialog.Builder(Programs.this);
// alert.setIcon(R.drawable.ic_alert_icon);
alert.setTitle("Executive Master of Business Administration (EMBA)");
alert.setMessage("Applicants must have a bachelor’s degree in a related field, plus minimum two years managerial or professional experience or a masters degree in a relevant field, plus minimum one year managerial or professional experience." + "\n" + "\n"
+ "All elective courses are determined by the University at the beginning of each quarter and are offered to the entire class. The students are required to take the complete block of optional courses offered by the University in any quarter." + "\n" + "\n"
+ "In addition to the requirement for earned credits, a cumulative grade-point-average (GPA) of minimum 2.2 for all executive masters degree programs on a scale of 0.0 - 4.0 must be attained." + "\n" + "\n"
+ "For each major in EMBA, the University determines the optional courses at the beginning of each quarter, to be offered to the entire class taking a particular concentration. All students must take the complete set of optional courses determined and offered by the university for each quarter."
);
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alert.create();
alert.show();
}
else if(position == 3)
{
AlertDialog.Builder alert = new AlertDialog.Builder(Programs.this);
// alert.setIcon(R.drawable.ic_alert_icon);
alert.setTitle("Master of Science (MS) / MBA");
alert.setMessage("1- BBA (Hons) or BS (Hons) or equivalent qualification reflecting 16 years of education; or MBA (16 years) for admission to MS." + "\n" + "\n"
+ "In addition to eligibility requirements, all candidates are required to qualify a Written Test and an Interview." + "\n" + "\n"
);
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alert.create();
alert.show();
}
else if(position == 4)
{
AlertDialog.Builder alert = new AlertDialog.Builder(Programs.this);
// alert.setIcon(R.drawable.ic_alert_icon);
alert.setTitle("Bachelor of Science (BS)");
alert.setMessage("1- High School graduation (12 years of school education)" + "\n"
+ "2- Higher Secondary School Certificate or Intermediate Certificate in science, arts, or commerce (FA, FSc, I.Com)" + "\n"
+ "3- Diploma in Commerce with Certificate in Commerce (C.Com+D.Com) GCE O’Levels (minimum eight subjects) plus A’Levels (min 3 subjects)" + "\n"
+ "4- International Baccalaureate" + "\n" + "\n"
+ "In addition to the minimum qualification, candidates are required to qualify a Written Test and an Interview for admission to BS Program."
);
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alert.create();
alert.show();
}
else if(position == 5)
{
AlertDialog.Builder alert = new AlertDialog.Builder(Programs.this);
// alert.setIcon(R.drawable.ic_alert_icon);
alert.setTitle("Master of Science (MS)");
alert.setMessage("1- BS, BCS, BSc, BSc Engg., BSc Agri. BSc Comp Sc or equivalent bachelor’s degree qualification with Computer Science subjects or Maths and Physics." + "\n" + "\n"
+ "In addition to the minimum qualification, candidates are required to qualify a Written Test and an Interview for admission to MS Program."
);
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alert.create();
alert.show();
}
else if(position == 6)
{
AlertDialog.Builder alert = new AlertDialog.Builder(Programs.this);
// alert.setIcon(R.drawable.ic_alert_icon);
alert.setTitle("Executive Master of Science (MS)");
alert.setMessage("Applicants must have a relevant bachelor’s degree, plus: a postgraduate diploma in computer science or a combination of certificate / diploma courses in computer science equivalent to a postgraduate diploma or equivalent professional qualifications / experience." + "\n" + "\n"
+ "For the EMS Program, the University determines the optional courses at the beginning of each quarter, to be offered to the entire class taking a particular concentration. All students must take the complete set of optional courses determined and offered by the university for each quarter." + "\n" + "\n"
+ "In addition to the minimum qualification, candidates are required to qualify a Written Test and an Interview for admission to EMS Program."
);
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alert.create();
alert.show();
}
else if(position == 7)
{
AlertDialog.Builder alert = new AlertDialog.Builder(Programs.this);
// alert.setIcon(R.drawable.ic_alert_icon);
alert.setTitle("M.Sc Electronics");
alert.setMessage("1- BS, BCS, BA, BSc, BSc Engg., BSc Agri. BSc Comp Sc or equivalent bachelor’s degree qualification with either Maths or physics at bachelors level." + "\n" + "\n"
+ "In addition to the minimum qualification, a candidate must qualify a Written Test and an Interview for admission to the M.Sc. Program."
);
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alert.create();
alert.show();
}
else if(position == 8)
{
AlertDialog.Builder alert = new AlertDialog.Builder(Programs.this);
// alert.setIcon(R.drawable.ic_alert_icon);
alert.setTitle("M.Sc Telecommunication");
alert.setMessage("1- BS, BCS, BA, BSc, BSc Engg., BSc Agri. BSc Comp Sc or equivalent bachelor’s degree qualification with either Maths or physics at bachelors level." + "\n" + "\n"
+ "In addition to the minimum qualification, a candidate must qualify a Written Test and an Interview for admission to the M.Sc. Program."
);
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alert.create();
alert.show();
}
else if(position == 9)
{
AlertDialog.Builder alert = new AlertDialog.Builder(Programs.this);
// alert.setIcon(R.drawable.ic_alert_icon);
alert.setTitle("M.Sc Mathematics");
alert.setMessage("1- BS, BCS, BA, BSc, BSc Engg., BSc Agri. BSc Comp Sc or equivalent bachelor’s degree qualification with Maths at bachelors level." + "\n" + "\n"
+ "In addition to the minimum qualification, a candidate must qualify a Written Test and an Interview for admission to the M.Sc. Program."
);
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alert.create();
alert.show();
}
else if(position == 10)
{
AlertDialog.Builder alert = new AlertDialog.Builder(Programs.this);
// alert.setIcon(R.drawable.ic_alert_icon);
alert.setTitle("B-Tech (Pass)");
alert.setMessage("1- Diploma of Associate Engineering, DAE (three years) or equivalent" + "\n" + "\n"
+ "In addition to the minimum qualification, a candidate must qualify a Written Test and an Interview for admission to the B-Tech (Pass) Program."
);
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alert.create();
alert.show();
}
else if(position == 11)
{
AlertDialog.Builder alert = new AlertDialog.Builder(Programs.this);
// alert.setIcon(R.drawable.ic_alert_icon);
alert.setTitle("B-Tech (Honors)");
alert.setMessage("1- B-Tech (Pass) or equivalent Bachelor's degree qualifications" + "\n" + "\n"
+ "In addition to the minimum qualification, a candidate must qualify a Written Test and an Interview for admission to the B-Tech (Honors) Program."
);
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alert.create();
alert.show();
}
else if(position == 12)
{
AlertDialog.Builder alert = new AlertDialog.Builder(Programs.this);
// alert.setIcon(R.drawable.ic_alert_icon);
alert.setTitle("M-Tech");
alert.setMessage("1- B-Tech (Hons), B-Tech (4 year), BE/B.Sc. Engg. or equivalent bachelor's degree qualification" + "\n" + "\n"
+ "In addition to the minimum qualification, a candidate must qualify a Written Test and an Interview for admission to the M-Tech Program."
);
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alert.create();
alert.show();
}
else if(position == 13)
{
AlertDialog.Builder alert = new AlertDialog.Builder(Programs.this);
// alert.setIcon(R.drawable.ic_alert_icon);
alert.setTitle("M.Sc Economics");
alert.setMessage("1- BS, BA, BSc or equivalent bachelor’s degree qualification, with relevant subjects at bachelor's level" + "\n" + "\n"
+ "For M.Sc. Economics, student must have taken Economics at bachelor's level for M.Sc. Psychology, Students must have taken Psychology at bachelors level and for M.Sc. IR, student must have either Political Science, or Civics, Pakistan Studies, History, Geography, Development Studies or equivalent subject at bachelor's level." + "\n" + "\n"
+ "In addition to the minimum qualification, a candidate must qualify a Written Test and an Interview for admission to the M.Sc. Program."
);
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alert.create();
alert.show();
}
else if(position == 14)
{
AlertDialog.Builder alert = new AlertDialog.Builder(Programs.this);
// alert.setIcon(R.drawable.ic_alert_icon);
alert.setTitle("M.Sc Applied Psychology");
alert.setMessage("1- BS, BA, BSc or equivalent bachelor’s degree qualification, with relevant subjects at bachelor's level" + "\n" + "\n"
+ "For M.Sc. Economics, student must have taken Economics at bachelor's level for M.Sc. Psychology, Students must have taken Psychology at bachelors level and for M.Sc. IR, student must have either Political Science, or Civics, Pakistan Studies, History, Geography, Development Studies or equivalent subject at bachelor's level." + "\n" + "\n"
+ "In addition to the minimum qualification, a candidate must qualify a Written Test and an Interview for admission to the M.Sc. Program."
);
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alert.create();
alert.show();
}
else if(position == 15)
{
AlertDialog.Builder alert = new AlertDialog.Builder(Programs.this);
// alert.setIcon(R.drawable.ic_alert_icon);
alert.setTitle("M.Sc International Relations");
alert.setMessage("1- BS, BA, BSc or equivalent bachelor’s degree qualification, with relevant subjects at bachelor's level" + "\n" + "\n"
+ "For M.Sc. Economics, student must have taken Economics at bachelor's level for M.Sc. Psychology, Students must have taken Psychology at bachelors level and for M.Sc. IR, student must have either Political Science, or Civics, Pakistan Studies, History, Geography, Development Studies or equivalent subject at bachelor's level." + "\n" + "\n"
+ "In addition to the minimum qualification, a candidate must qualify a Written Test and an Interview for admission to the M.Sc. Program."
);
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alert.create();
alert.show();
}
else if(position == 16)
{
AlertDialog.Builder alert = new AlertDialog.Builder(Programs.this);
// alert.setIcon(R.drawable.ic_alert_icon);
alert.setTitle("M.Sc International Diplomacy");
alert.setMessage("A candidate for admission to M.Sc International Diplomacy Program must fulfil both of the following two conditions:" + "\n" + "\n"
+ "1- B.A, B.Sc or equivalent bachelor’s degree" + "\n" + "\n"
+ "2- Must be an Ambassador, serving diplomat, military attache or senior officer in two foreign service, Heads and Country Representative of International Organization." + "\n" + "\n"
+ "In addition to the minimum qualification, a candidate must qualify a Written Test and an Interview for admission to the M.Sc. Program.");
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alert.create();
alert.show();
}
else if(position == 17)
{
AlertDialog.Builder alert = new AlertDialog.Builder(Programs.this);
// alert.setIcon(R.drawable.ic_alert_icon);
alert.setTitle("B.Ed (Education)");
alert.setMessage("1- BS/ B.Sc or equivalent" + "\n" + "\n"
+ "In addition to the minimum qualification, a candidate must qualify a Written Test and an Interview for admission to theB.Ed (Education) Program."
);
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alert.create();
alert.show();
}
else if(position == 18)
{
AlertDialog.Builder alert = new AlertDialog.Builder(Programs.this);
// alert.setIcon(R.drawable.ic_alert_icon);
alert.setTitle("M.Ed (Education)");
alert.setMessage("1- B.Ed or equivalent" + "\n" + "\n"
+ "In addition to the minimum qualification, a candidate must qualify a Written Test and an Interview for admission to the M.Ed Program."
);
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alert.create();
alert.show();
}
else if(position == 19)
{
AlertDialog.Builder alert = new AlertDialog.Builder(Programs.this);
// alert.setIcon(R.drawable.ic_alert_icon);
alert.setTitle("M.A (Education)");
alert.setMessage("1- BS, BA, B.Sc or equivalent bachelor’s degree qualification." + "\n" + "\n"
+ "In addition to the minimum qualification, a candidate must qualify a Written Test and an Interview for admission to the M.A Program."
);
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alert.create();
alert.show();
}
}
public void SelectItem(int position) {
list.setItemChecked(position, true);
}
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@SuppressLint("NewApi")
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main_menu, menu);
MenuItem shareItem = (MenuItem) menu.findItem(R.id.action_share);
ShareActionProvider mShare = (ShareActionProvider)shareItem.getActionProvider();
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, "Share with your friends and fellows");
mShare.setShareIntent(shareIntent);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.callUs) {
AlertDialog.Builder alert = new AlertDialog.Builder(Programs.this);
alert.setMessage("You want to call in Preston University");
alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent call = new Intent (Intent.ACTION_DIAL);
call.setData(Uri.parse("tel:(051)111-707-808"));
startActivity(call);
}
});
alert.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alert.create();
alert.show();
return true;
}
if(id == android.R.id.home) {
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onBackPressed() {
moveTaskToBack(true);
Programs.this.finish();
}
}
CustomProgramsListAdapter.java
package net.meask.prestonstudent;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import net.meask.prestonstudent.R;
public class CustomProgramsListAdapter extends ArrayAdapter<String> {
private final Activity context;
private final String[] itemname;
private final Integer[] imgid;
public CustomProgramsListAdapter(Activity context, String[] itemname, Integer[] imgid) {
super(context, R.layout.mylist, itemname);
// TODO Auto-generated constructor stub
this.context=context;
this.itemname=itemname;
this.imgid=imgid;
}
public View getView(int position,View view,ViewGroup parent) {
LayoutInflater inflater=context.getLayoutInflater();
View rowView=inflater.inflate(R.layout.mylist, null,true);
TextView txtTitle = (TextView) rowView.findViewById(R.id.item);
ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);
TextView extratxt = (TextView) rowView.findViewById(R.id.textView1);
txtTitle.setText(itemname[position]);
imageView.setImageResource(imgid[position]);
extratxt.setText("Programs Offered & Eligibility ");
return rowView;
};
}
CustomDrawerAdapter.java
package net.meask.prestonstudent;
import java.util.List;
import net.meask.prestonstudent.R;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class CustomDrawerAdapter extends ArrayAdapter<DrawerItem> {
Context context;
List<DrawerItem> drawerItemList;
int layoutResID;
public CustomDrawerAdapter(Context context, int layoutResourceID,
List<DrawerItem> listItems) {
super(context, layoutResourceID, listItems);
this.context = context;
this.drawerItemList = listItems;
this.layoutResID = layoutResourceID;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
DrawerItemHolder drawerHolder;
View view = convertView;
if (view == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
drawerHolder = new DrawerItemHolder();
view = inflater.inflate(layoutResID, parent, false);
drawerHolder.ItemName = (TextView) view
.findViewById(R.id.drawer_itemName);
drawerHolder.icon = (ImageView) view.findViewById(R.id.drawer_icon);
view.setTag(drawerHolder);
} else {
drawerHolder = (DrawerItemHolder) view.getTag();
}
DrawerItem dItem = (DrawerItem) this.drawerItemList.get(position);
drawerHolder.icon.setImageDrawable(view.getResources().getDrawable(
dItem.getImgResID()));
drawerHolder.ItemName.setText(dItem.getItemName());
return view;
}
private static class DrawerItemHolder {
TextView ItemName;
ImageView icon;
}
}