imageButton이 포함 된 레이아웃을 부 풀리고 있습니다. 클릭 할 때마다 작업을 수행 할 수 있도록 imageButton에 이벤트를 지정하려고합니다. 다음은 (C#에서) 내 코드입니다 :레이아웃 인플레이터의 "비 정적 멤버에 액세스하는 데 객체 참조가 필요합니다."
객체 참조가 비 정적 필드 'ContextWrapper.SartActivity (의도)'하는 이유는 무엇입니까 액세스하는 데 필요한
public class HomeScreenAdapter : BaseAdapter<TableItem>
{
List<TableItem> items;
Activity context;
public HomeScreenAdapter(Activity context, List<TableItem> items)
: base()
{
this.context = context;
this.items = items;
}
public override long GetItemId(int position)
{
return position;
}
public override TableItem this[int position]
{
get { return items[position]; }
}
public override int Count
{
get { return items.Count; }
}
public override View GetView(int position, View convertView, ViewGroup parent)
{
var item = items[position];
View view = convertView;
if (view == null) // no view to re-use, create new
view = context.LayoutInflater.Inflate(Resource.Layout.ticket_news, null); view.FindViewById<ImageView>(Resource.Id.Image).SetImageBitmap(item.imageBitmap);
view.FindViewById<ImageButton>(Resource.Id.imageButton2).Click += delegate
{
Intent sharingIntent = new Intent(Intent.ActionSend);
sharingIntent.SetType("text/plain");
sharingIntent.PutExtra(Intent.ExtraText, "Message");
StartActivity(Intent.CreateChooser(sharingIntent, "Share via")); // here where I am getting the error
PackageManager pm = PackageManager; // and here I am getting the same error again
};
return view;
}
}
이 오류와 어떻게 해결할 수 있습니까? 는
컨텍스트 참조를 사용하여 context.StartActivity (....)와 같은 새 활동을 시작하십시오. –
감사합니다. 효과가있었습니다! 만약 내가'PackageManager pm = PackageManager; '와 같은 패키지 관리자를 초기화하고 싶다면'StartActivity'와 같은 오류가 발생합니다. 이게 어떻게 풀릴 수 있니? –
여기에서 코드를 공유해 주시면 알려 드리겠습니다.하지만 같은 문제를 해결하는 데 도움이 될 수 있도록 의견을 통해 제안하는대로 대답을 받아 들여야합니다. –