Tag: android

添加textView到拖放界面 – Android / Java

我有一个gridView,我从以下教程/示例构建: Improved Drag-Drop for an Android GridView 原样 – 示例的源(可从下面的链接下载)允许用户拖放新的方形imageView并将其放在gridview中。 我现在想要完成的是能够创建一个可以拖放的textView(与imageView一起),实际上创建一个带有可以拖放的标题的文件夹。 到目前为止 – 我已经设法创建我自己的自定义(新的瓷砖等以及一个editText,点击成为textView)版本的gridView – 以及istantiated一个textView – 我似乎无法让它移动拖动时使用imageView。 /** * Interface defining an object that reacts to objects being dragged over and dropped onto it. * */ public interface DropTarget { /** * Handle an object being dropped on the DropTarget * * @param source DragSource […]

Android改造设计模式

我正在使用Retrofit与我的REST API进行交互,并且想知道是否有人有任何设计建议。 我的应用程序包含以下包: 楷模 服务 活动 片段 服务包包含Retrofit的接口。 例如: public interface FooService { @FormUrlEncoded @POST(“foo/do”) @Headers(“Content-Type: application/x-www-form-urlencoded; charset=UTF-8”) Call do(); } 模型包含……嗯,不同的模型。 例如, FooBar 。 到目前为止一切都很好 – 就像Retrofit文档一样。 我创建了一个API类,它处理Retrofit构建逻辑( Retrofit retrofit = new Retrofit.Builder()等),并公开一个静态字段:retrofit。在我的活动中,我可以按如下方式执行我的请求: FooService service = API.retrofit.create(FooService.class); Call call = service.do(); try { retrofit2.Response response = call.execute(); // …do stuff… } catch(IOException) {} 随之而来的是我的问题:进一步抽象上述内容会更好吗? […]

了解Android中的Arraylist IndexOutOfBoundsException

我从我使用的任何Arraylist获得了很多IndexOutOfBoundsException 。 大多数时候它工作正常但有时我在我的项目中使用的Arraylists上遇到这个恼人的错误。 主要原因始终是 java.util.ArrayList.throwIndexOutOfBoundsException: Invalid index 3, size is 3 要么 java.util.ArrayList.throwIndexOutOfBoundsException: Invalid index 0, size is 0 帮助我理解这个错误的主要原因,因为无论我搜索了多少答案,他们都没有完全帮助我。

驱动程序JDBC PostgreSQL与Android

我正在尝试使用JDBC驱动程序将我的Android应用程序连接到服务器(PostgreSQL),但是我有这个错误: java.lang.ClassNotFoundException: org.postgresql.Driver … Caused by: java.lang.NoClassDefFoundError: org/postgresql/Driver … 12 more Caused by: java.lang.ClassNotFoundException: org.postgresql.Driver … java.sql.SQLException: No suitable driver 我尝试了很多东西,比如在路径中添加驱动程序的地址,但没有任何效果。 我按照本教程: http ://appliedcoffeetechnology.tumblr.com/post/10657124340并在Build Path中添加了驱动程序JDBC4(我也尝试过JDBC3)。 每个人都可以帮助我吗?

如何正确使用向后兼容的Vector Drawable与最新的Android支持库?

Vector drawable已经在不久前添加到支持库中了,自那时起API中有很多变化:Gradle标志,初始化块,选择器,自定义XML属性等。问题是 – 如何正确使用它(在这些情况下支持lib v25): ImageView的 TextView drawable 菜单图标 通知图标 XML和编程。

如何从后台以编程方式恢复Android Activity

情况: 假设我目前正在推出应用程序活动A. 过了一段时间我按“主页”按钮。 应用程序A转到后台。 这时,我开始使用另一个应用程序B – 例如youtube等。 在应用程序A中发生了一些事情(在这个上下文中无关紧要,假设计时器已完成计算时间),该应用程序A当前被最小化为背景。 在事件发生时,应用程序A活动自动从后台恢复。 题: 如何完成第5步? 基本上我需要知道如何以编程方式从后台恢复应用程序。 我试图启动意图“重启”我的应用程序活动,但它没有奏效: Intent intent = new Intent(context, MainActivity.class); intent.setAction(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); context.startActivity(intent); 我的清单文件:

android.content.res.Resources $ NotFoundException

@Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.screenlocked); //Retrieve stored ID final String STORAGE = “Storage”; SharedPreferences unique = getSharedPreferences(STORAGE, 0); LoginID = unique.getString(“identifier”, “”); //Retrieve stored phone number final String phoneNumber = unique.getString(“PhoneNumber”, “”); phoneView = (TextView) findViewById(R.id.phone); phoneView.setText(phoneNumber.toString()); //Retrieve user input input = (EditText) findViewById(R.id.editText1); userInput = input.getText().toString(); //Set login button login = (Button) […]

如何在领域浏览器中查看我的Realm文件?

我刚刚发现了Realm,并且想要更详细地探索它,所以我决定创建示例应用程序并搞砸它。 到现在为止还挺好。 但是,我还没有解决的一件事是如何在Realm Browser中查看我的数据库。 如何才能做到这一点?

为什么在Activity中访问Fragment的TextView会抛出错误

MainActivity类: /* all necessary imports */ public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { /* Other variable initialized here… */ FragOne fo; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); fo.setTextViewText(“This is added from Activity”); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawer, toolbar, R.string.navigation_drawer_open, […]

Android – 获取从文件资源管理器中选择的.txt文件的真实路径

我正在开发一个应用程序,我希望能够在.txt文件中导出和导入应用程序中的一些数据。 该应用程序的最低API为21。 导出部分运行良好,但我在导入部分遇到问题。 我打开文件浏览器: butImportPatient.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_OPEN_DOCUMENT); intent.setType(“*/*”); startActivityForResult(intent, IMPORTPATIENT_ACTIVITY_REQUEST_CODE); } }); 这看起来很有效。 但我的onActivityResult不起作用,我没有找到如何从Uri获取文件。 现在,这是我的代码: @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == IMPORTPATIENT_ACTIVITY_REQUEST_CODE && resultCode == RESULT_OK) { File file = new File(data.getData().getPath()) ; String path = […]