Tag: android activity

为什么我无法读取只读文件?

我有这个方法应该读取一个文件: /* Read file’s content */ private ArrayList readFromFile() { File file = new File(“jokesBody1.bjk”); ArrayList list = new ArrayList(); try { file.createNewFile(); ObjectInputStream ois = new ObjectInputStream( new FileInputStream( file ) ); try { list = (ArrayList)ois.readObject(); } catch (ClassNotFoundException e) { e.printStackTrace(); } ois.close(); } catch (IOException e) { Log.e(“log activity”, “Can not […]

如何让应用等待,然后开始活动或回去?

我希望我的活动显示3秒的屏幕,然后返回上一屏幕。 但是当我使用时 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.welcome_layout); TextView tvResult = (TextView)findViewById(R.id.textView1) Thread.sleep(3000); Intent i = new Intent(this,myActivity.class); startActivity(i); 但不幸的是,这不起作用。 此事件显示活动等待3秒后返回。 但是,我希望它在返回之前显示其内容。 我该怎么做 ?

无法启动新活动

美好的一天,我尝试从另一个开始新的活动。 但它总是崩溃。 我的代码。 它是ListView上的事件。 list.setOnItemClickListener(new OnItemClickListener(){ public void onItemClick(AdapterView parent, View view, int position, long id){ Student selected = (Student)list.getItemAtPosition(position); String selectedTitle = selected.FirstName; //ideally this would probably be done with accessors int selectedId = selected.studentId; String selectedDescription = selected.LastName; Intent i = new Intent(view.getContext(), StudentInfoActivity.class); i.putExtra(“studentId”, selectedId); try{ startActivity(i); }catch (Exception e) { // […]

将图像从一个活动发送到另一个活动

我试图将图像从一个活动发送到另一个活动,但我不知道如何设置imageview。 这是我发送图像和其他东西的方式 Intent item_intent = new Intent(MainActivity.this, Item.class); item_intent.putExtra(“name”,”test name arif”); item_intent.putExtra(“quantity”,”99″); //*************************here is the image*************************** item_intent.putExtra(“image”,R.drawable.access); MainActivity.this.startActivity(item_intent); 这是我如何尝试读取图像并将其设置为ImageView但我收到语法错误。 Intent intent = getIntent(); ImageView img_view = (ImageView) findViewById(R.id.item_image); // this where I am having problem below****************************** img_view.setImageBitmap(intent.getByteArrayExtra(“image”)); 我该如何设置ImageView?

如何使用两个按钮实现多个datepickerfunction并保存选择的日期?

我想创建一个活动,其中我想要有两个按钮和多个标签。 用户可以单击按钮从中选择日期。 而这些选定日期可以在标签中显示,以便用户可以知道用户已经选择了哪些日期。 任何人都可以指导我如何做到这一点。 使用多个日期选择function,两个按钮上只有两个日期选择器。 我该如何保存这些日期。 因此,每当用户离开此活动并再次访问时,他可能会知道。

如何解决布局中更多数字的Editext并从中获取价值?

看到这张图: 我在android中设计了一个数独游戏,完成了这样的布局,所以81 Editext就在那里。 我想获得Editext中的所有值,因此很难在活动中声明和管理81个视图。 你能建议我一个有效处理我的问题的方法吗?

如何在活动之间传递一个double数组(boolean )?

我看不到要获得一个双布尔数组来传递给另一个活动。 我使用putExtra,当我检索它并将其转换为boolean[][] ,它声明它不能转换和崩溃。 但是,Boolean []有效。 我如何在活动之间传递boolean[][] ?

什么时候活动的实例变量被初始化?

在我的Android应用程序中,我有一个奇怪的错误。 像下面这样的实例变量在运行时意外地分配给它的默认值(在这种情况下为false)。 什么时候在android活动中初始化这种类型的变量? public class MainActivity extends Activity { private boolean isInitialized = false; // <- When do this variable get initialized? }

带ActionBarActivity的NoClassDefFoundError Android

我目前有一个ActionBarActivity ,它总是返回NoClassDefFoundError 。 我读过它可能是ADT的一个问题,但我无法确定,因此我的问题。 我已经从Android样本中导入了ActionBar示例 android-sdk\samples\android-14\ActionBarCompat 我已将ActionBarCompat项目标记为Project – > Properties下的库,但我仍然收到错误。 重申: public class SearchActivity extends ActionBarActivity { // Doesn’t work, yields exception public class SearchActivity extends Activity { // Works perfectly 有没有其他人遇到类似的错误,也许找到了解决方案? 提前致谢。

使用编程在android上设置触摸输入

我想使用编程来模仿屏幕上位置(x,y)的“触摸”。 我看到了这个链接,但它只教你如何注入字符。 我想在位置(x,y)注入触摸 我如何使用Android SDK(java)来做到这一点?