majid.ostadi
یک شنبه 06 مهر 1393, 17:18 عصر
با سلام خدمت اساتید محترم
تو یه تایپیک قبلم فکر میکنم نتونستم مشکلم رو واضح و صریح بیان کنم و دوستان رو دچار سردرگمی کردم. در این تاپیک میخوام کامل مشکلم رو موشکافی کنم تا بلکه مشکلم حل بشه.
با عرض پوزش از مدیر تالار که یه بحث رو روبار مطرح میکنم
در زیر عکس گذاشتم تا کسی دچار سردرگمی نشه
123975 123976
همونجوری که تو عکس ها گفتم من برنامه ام دوتا لایوت داره. داخل لایوت اصلی برنامه یه باتن هست که تا کاربر روش کلیک میکنه لایوت دوم باز میشه و گالری داخلش نمایش داده میشه.
مشکل من اینه که کالری رو نمایش نمیده و لایوت خالیه.
حالا دوستانی که میدونن مشکلش چیه یه زحمتی بکشن و من رو از این سردرگمی در بیارن
کد های برنامه هم می ذارم
کد کلاس گالری که ازش استفاده کردم :
package com.example.gallery;
import android.os.Bundle;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.AdapterView.OnItemClickListener;
public class MainActivity extends Activity {
ImageView selectedImage;
private Integer[] mImageIds =
{
R.drawable.image1,
R.drawable.image2,
R.drawable.image3,
R.drawable.image4,
R.drawable.image5,
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View inflatedView = getLayoutInflater().inflate(R.layout.secondlayout, null);
Gallery gallery = (Gallery) inflatedView.findViewById(R.id.gallery1);
gallery.setSpacing(1);
gallery.setAdapter(new GalleryImageAdapter(this));
// clicklistener for Gallery
gallery.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
{
selectedImage.setImageResource(mImageIds[position]);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item)
{
if(item.getItemId() == R.id.Learnings)
{
}
if(item.getItemId() == R.id.Gallery)
{
startActivity(new Intent(MainActivity.this, GoGallery.class));
}
return super.onOptionsItemSelected(item);
}
}
کد کلاس که کاربر رو از لایوت اصلی به لایوت دوم میبره :
package com.example.gallery;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class GoGallery extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.secondlayout);
}
}
کد main activity :
package com.example.gallery;
import android.os.Bundle;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.AdapterView.OnItemClickListener;
public class MainActivity extends Activity {
ImageView selectedImage;
private Integer[] mImageIds =
{
R.drawable.image1,
R.drawable.image2,
R.drawable.image3,
R.drawable.image4,
R.drawable.image5,
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = (Button) findViewById(R.id.btn_Gallery);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
startActivity(new Intent(MainActivity.this, GoGallery.class));
}
});
View inflatedView = getLayoutInflater().inflate(R.layout.secondlayout, null);
Gallery gallery = (Gallery) inflatedView.findViewById(R.id.gallery1);
gallery.setSpacing(1);
gallery.setAdapter(new GalleryImageAdapter(this));
// clicklistener for Gallery
gallery.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
{
selectedImage.setImageResource(mImageIds[position]);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
}
کد لایوت اصلی :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="@+id/btn_Gallery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="151dp"
android:text="نمايش گالري" />
</RelativeLayout>
کد لایوت دوم :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Gallery
android:id="@+id/gallery1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp" />
</LinearLayout>
تو یه تایپیک قبلم فکر میکنم نتونستم مشکلم رو واضح و صریح بیان کنم و دوستان رو دچار سردرگمی کردم. در این تاپیک میخوام کامل مشکلم رو موشکافی کنم تا بلکه مشکلم حل بشه.
با عرض پوزش از مدیر تالار که یه بحث رو روبار مطرح میکنم
در زیر عکس گذاشتم تا کسی دچار سردرگمی نشه
123975 123976
همونجوری که تو عکس ها گفتم من برنامه ام دوتا لایوت داره. داخل لایوت اصلی برنامه یه باتن هست که تا کاربر روش کلیک میکنه لایوت دوم باز میشه و گالری داخلش نمایش داده میشه.
مشکل من اینه که کالری رو نمایش نمیده و لایوت خالیه.
حالا دوستانی که میدونن مشکلش چیه یه زحمتی بکشن و من رو از این سردرگمی در بیارن
کد های برنامه هم می ذارم
کد کلاس گالری که ازش استفاده کردم :
package com.example.gallery;
import android.os.Bundle;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.AdapterView.OnItemClickListener;
public class MainActivity extends Activity {
ImageView selectedImage;
private Integer[] mImageIds =
{
R.drawable.image1,
R.drawable.image2,
R.drawable.image3,
R.drawable.image4,
R.drawable.image5,
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View inflatedView = getLayoutInflater().inflate(R.layout.secondlayout, null);
Gallery gallery = (Gallery) inflatedView.findViewById(R.id.gallery1);
gallery.setSpacing(1);
gallery.setAdapter(new GalleryImageAdapter(this));
// clicklistener for Gallery
gallery.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
{
selectedImage.setImageResource(mImageIds[position]);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item)
{
if(item.getItemId() == R.id.Learnings)
{
}
if(item.getItemId() == R.id.Gallery)
{
startActivity(new Intent(MainActivity.this, GoGallery.class));
}
return super.onOptionsItemSelected(item);
}
}
کد کلاس که کاربر رو از لایوت اصلی به لایوت دوم میبره :
package com.example.gallery;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class GoGallery extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.secondlayout);
}
}
کد main activity :
package com.example.gallery;
import android.os.Bundle;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.AdapterView.OnItemClickListener;
public class MainActivity extends Activity {
ImageView selectedImage;
private Integer[] mImageIds =
{
R.drawable.image1,
R.drawable.image2,
R.drawable.image3,
R.drawable.image4,
R.drawable.image5,
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = (Button) findViewById(R.id.btn_Gallery);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
startActivity(new Intent(MainActivity.this, GoGallery.class));
}
});
View inflatedView = getLayoutInflater().inflate(R.layout.secondlayout, null);
Gallery gallery = (Gallery) inflatedView.findViewById(R.id.gallery1);
gallery.setSpacing(1);
gallery.setAdapter(new GalleryImageAdapter(this));
// clicklistener for Gallery
gallery.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
{
selectedImage.setImageResource(mImageIds[position]);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
}
کد لایوت اصلی :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="@+id/btn_Gallery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="151dp"
android:text="نمايش گالري" />
</RelativeLayout>
کد لایوت دوم :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Gallery
android:id="@+id/gallery1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp" />
</LinearLayout>