我正在尝试使用https://github.com/bauerca/drag-sort-listview来合并拖放操作,我试图编写一个应用程序。我不知道我的错误是如何导入DragSortListView或我的代码。DragSortListView - Android Studio无法识别dropListener和removeListener
我最初通过使用maven central来导入库,并且在模块:app的build.gradle中添加了依赖编译“asia.itivity.android:drag-sort-listview:1.0”。我遇到的问题是,在我调用listItems.setDropListener(onDrop)和listItems.setRemoveListener(onRemove)时,我将在下面列出的代码中,Android Studio无法解析符号'.setDropListener'和'setRemovelistener,但它确实识别其他所有相关内容拖动排序列表视图。我遵循此示例Bauerca drag-sort-listview simple example以及存储库本身中的示例。
我改变主要活动扩展ActionBarActivity扩展ListActivity没有区别。我使用安装在我的计算机上的git gui(这对我来说是全新的)来将git存储库https://github.com/JayH5/drag-sort-listview克隆到我的计算机上的一个文件夹中,然后使用Android Studio将/ demo和/ library作为模块添加到我的项目中,并添加了库作为我的主要模块应用程序的依赖,但我仍然得到错误。我也尝试添加演示作为依赖项,但出现错误,因此我删除了该依赖项。我非常感谢任何帮助!我最初尝试使用ListViewAnimations库,但无法让它工作(stableId问题)。
非常感谢!泰伦
package dtcj.bandtasker;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import com.mobeta.android.dslv.DragSortListView;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
public class MainActivity extends ListActivity {
//create list of trigger phrases
private ArrayList<String> items;
private ArrayAdapter<String> itemsAdapter;
private DragSortListView.DropListener onDrop = new DragSortListView.DropListener()
{
@Override
public void drop(int from, int to)
{
if (from != to)
{
String item = itemsAdapter.getItem(from);
itemsAdapter.remove(item);
itemsAdapter.insert(item, to);
}
}
};
private DragSortListView.RemoveListener onRemove = new DragSortListView.RemoveListener()
{
@Override
public void remove(int which)
{
String item = itemsAdapter.getItem(which);
itemsAdapter.remove(item);
}
};
@Override
public DragSortListView getListView() {
return (DragSortListView) super.getListView();
}
//Methods to read and write user entered items to the data file
private void readItems() {
File filesDir = getFilesDir();
File todoFile = new File(filesDir, "triggers.txt");
try {
items = new ArrayList<String>(FileUtils.readLines(todoFile));
} catch (IOException e) {
items = new ArrayList<String>();
}
}
private void writeItems() {
File filesDir = getFilesDir();
File todoFile = new File(filesDir, "triggers.txt");
try {
FileUtils.writeLines(todoFile, items);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
items = new ArrayList<String>(8);
readItems();
itemsAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,
items);
listItems.setAdapter(itemsAdapter);}
DragSortListView listItems = (DragSortListView) getListView();
//Problem is here
listItems.setDropListener(onDrop);
listItems.setRemoveListener(onRemove);
//TO DO
// Action Bar- "How to use", About
//Add phrases to list
public void onAddItem(View v) {
//check that there are fewer than 8 trigger phrases in the array
if (items.size() <= 7){
EditText getNewItem = (EditText) findViewById(R.id.getNewItem);
String itemText = getNewItem.getText().toString();
itemsAdapter.add(itemText);
getNewItem.setText("");
writeItems();}
else{
//Warn user they have reached maximum number of Trigger Phrases
// Creating alert Dialog with one Button
final AlertDialog.Builder maxAlert = new AlertDialog.Builder(this);
maxAlert.setMessage("Sorry! Eight is the maximum number of trigger phrases. Please delete a phrase before adding a new one.")
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//do things
}
});
// Showing Alert Message
maxAlert.show();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
的build.gradle的模块:应用
defaultConfig {
applicationId "dtcj.bandtasker"
minSdkVersion 17
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'org.apache.commons:commons-io:1.3.2'
compile files('libs/microsoft-band-1.3.10622.3.jar')
compile 'com.nineoldandroids:library:2.4.0'
compile project(':library')
}
settings.gradle
include ':app', ':demo', ':library'