使用onItemClickListener单击时,从数据库中获取的gridview中的图像不会全屏显示

时间:2015-06-18 12:07:38

标签: java android mysql listview gridview

我正在使用GridView从mysql Databse显示我的图像。 但是,当我尝试使用OnItemClickListener单击时在FullScreen中显示图像时,应用程序不会崩溃,但是它不会显示我的UI。

这是MainActivity的代码: -

public class MainActivity extends Activity implements OnClickListener {
// Log tag
private static final String TAG = MainActivity.class.getSimpleName();

// Movies json url
private static final String url = "http://eventassociate.com/wedding/photomania";
private ProgressDialog pDialog;
private List<Movie> movieList = new ArrayList<Movie>();

private GridView gridView;
private CustomListAdapter adapter;
Button blackcapture;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.gallary_activity_main);

    overridePendingTransition(R.anim.push_down_in, R.anim.push_down_out);

    gridView = (GridView) findViewById(R.id.list);

    blackcapture = (Button) findViewById(R.id.bottom_button);
    blackcapture.setOnClickListener(this);

    adapter = new CustomListAdapter(this, movieList);
    gridView.setAdapter(adapter);




    gridView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View v,
                int position, long id) {

            Movie m5 = movieList.get(position);

            Intent i = new Intent(getApplicationContext(),
                    FullImageActivity.class);

            i.putExtra("movieobject", m5);
            startActivity(i);


        }
    });











    pDialog = new ProgressDialog(this);
    // Showing progress dialog before making http request
    pDialog.setMessage("Loading...");
    pDialog.show();

    // changing action bar color
    getActionBar().setBackgroundDrawable(
            new ColorDrawable(Color.parseColor("#1b1b1b")));

    // Creating volley request obj
    JsonArrayRequest movieReq = new JsonArrayRequest(url,
            new Response.Listener<JSONArray>() {
                @Override
                public void onResponse(JSONArray response) {
                    Log.d(TAG, response.toString());
                    hidePDialog();

                    // Parsing json
                    for (int i = 0; i < response.length(); i++) {
                        try {

                            JSONObject obj = response.getJSONObject(i);
                            Movie movie = new Movie();
                            movie.setTitle(obj.getString("No"));
                            movie.setThumbnailUrl(obj.getString("flinks"));

                            // adding movie to movies array
                            movieList.add(movie);

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                    }

                    // notifying list adapter about data changes
                    // so that it renders the list view with updated data
                    adapter.notifyDataSetChanged();
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    VolleyLog.d(TAG, "Error: " + error.getMessage());
                    hidePDialog();

                }
            });

CustomAdapter的代码: -

公共类CustomListAdapter扩展BaseAdapter {     私人活动活动;

private LayoutInflater inflater;
List<Movie> movieItems;
ImageLoader imageLoader = AppController.getInstance().getImageLoader();

public CustomListAdapter(Activity activity, List<Movie> movieItems) {
    this.activity = activity;
    this.movieItems = movieItems;
}







@Override
public int getCount() {
    return movieItems.size();
}

@Override
public Object getItem(int location) {
    return movieItems.get(location);
}

@Override
public long getItemId(int position) {
    return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {




    if (inflater == null)
        inflater = (LayoutInflater) activity
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    if (convertView == null)
        convertView = inflater.inflate(R.layout.gallary_list_row, null);

    if (imageLoader == null)
        imageLoader = AppController.getInstance().getImageLoader();
    NetworkImageView thumbNail = (NetworkImageView) convertView
            .findViewById(R.id.thumbnail);








    // ...............................................

    TextView title = (TextView) convertView.findViewById(R.id.title);

    // getting movie data for the row
    Movie m = movieItems.get(position);

    // thumbnail image
    thumbNail.setImageUrl(m.getThumbnailUrl(), imageLoader);

    // title
    title.setText(m.getTitle());







    return convertView;

}

电影类代码: -

public class Movie implements Parcelable{
private String title,thumbnailUrl;



public Movie() {
    // TODO Auto-generated constructor stub
}

public Movie(String name, String thumbnailUrl
        ) {
    this.title = name;
    this.thumbnailUrl = thumbnailUrl;

}



public String getTitle() {
    return title;
}

public void setTitle(String name) {
    this.title = name;
}

public String getThumbnailUrl() {
    return thumbnailUrl;
}

public void setThumbnailUrl(String thumbnailUrl) {
    this.thumbnailUrl = "http://eventassociate.com/wedding/"+thumbnailUrl;
}

 // Parcelling part
public Movie(Parcel in){
    String[] data = new String[2];

    in.readStringArray(data);
    this.title = data[0];
    this.thumbnailUrl = data[1];

}








@Override
public int describeContents() {
    // TODO Auto-generated method stub
    return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
    dest.writeStringArray(new String[] {this.title,
                                        this.thumbnailUrl,
                                        });
}

}

FullImageActivity的代码: -

公共类FullImageActivity扩展了Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.full_image);

 // get intent data



    Intent i = getIntent();

    Movie myParcelableObject = (Movie) i.getParcelableExtra("movieobject");



   String alp =  myParcelableObject.getThumbnailUrl();


    Toast.makeText(getApplicationContext(), alp, Toast.LENGTH_LONG).show();



    ImageView imageView = (ImageView) findViewById(R.id.full_image_view);







}

}

1 个答案:

答案 0 :(得分:1)

您的BEGIN TRANSACTION; UPDATE B SET status = 1 , date = GETDATE() WHERE B.PersonId IN ( SELECT ID FROM A WHERE A.status = 2 ); UPDATE A SET status = 1 , date = GETDATE() WHERE A.status = 2; COMMIT;

中存在一些问题
  1. 您正在初始化FullImageActivity CustomListAdapter为什么?这里不需要。

  2. 您从上一个活动获得了职位。最好从捆绑中获取图像的ID。

  3. 如果从包中获取id,则点击数据库并根据id获取图像,并将图像分配给imageview。