我在仪表板活动中有textview txtQuantity.我为自定义适配器写了单独的类,它将包含已售出的产品.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dashboard);
list = (ListView) findViewById(R.id.listSoldItems);
txtAmount = (TextView) findViewById(R.id.txtAmount);
txtItems = (TextView) findViewById(R.id.txtItems);
// init listview
adapter = new Sold_item_adaptor(Dashboard.this, soldItemsList);
list.setAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)
我可以使用适配器从列表中删除项目.删除项的代码用适配器类编写.
public View getView(final int position, View convertView, ViewGroup parent) {
View vi = convertView;
if (convertView == null)
vi = inflater.inflate(R.layout.list_row_sold_item, null);
TextView txtListItem = (TextView) vi.findViewById(R.id.txtListItem);
final TextView txtQuantity = (TextView) vi.findViewById(R.id.txtQuantity);
ImageView imgCancel = (ImageView) vi.findViewById(R.id.imgCancel);
HashMap<String, String> mapData = new HashMap<String, String>();
mapData = data.get(position);
txtListItem.setText(mapData.get("product")); …Run Code Online (Sandbox Code Playgroud) 我想从代码中调用onCreateOptionsMenu,因为如果我使用:
menu.setGroupEnabled(0, false);
Run Code Online (Sandbox Code Playgroud)
附:
public Menu menu;
public boolean onCreateOptionsMenu(Menu menu) {
this.menu = menu;
menu.add(0,0,0,"Option");
return true;
}
Run Code Online (Sandbox Code Playgroud)
如果用户从未按下菜单按钮,则不起作用.我怎样才能做到这一点?
谢谢
PS:如果这是一个不好的做法让我知道
当我尝试从列表中对json对象进行parjse时,我收到错误com.google.gson.JsonPrimitive无法强制转换为com.google.gson.JsonObject
输入:
{
"r$contentRatings": [
{
"r$scheme": "urn:rt",
"r$rating": "criticSummaryScore=-1,criticSummaryCount=0,criticSummaryCertified=false,criticSummaryRotten=false,fanSummaryScore=75,fanSummaryCount=4"
}
]
}
Run Code Online (Sandbox Code Playgroud)
码:
JsonElement elem = null;
elem = jsonObject.get("r$contentRatings");
if(elem != null) {
JsonArray contentRatingsList = elem.getAsJsonArray();
if(contentRatingsList != null) {
for(int i=0; i< contentRatingsList.size(); i++) {
JsonObject scheme =contentRatingsList.get(i).getAsJsonObject().getAsJsonObject("r$scheme");
JsonObject rating =contentRatingsList.get(i).getAsJsonObject().getAsJsonObject("r$rating");
JsonArray subRatings = contentRatingsList.get(i).getAsJsonObject().getAsJsonObject("r$subRatings").getAsJsonArray();
Run Code Online (Sandbox Code Playgroud)
错误:
在for循环中,当我尝试jsonobject从列表中访问时,r$scheme我收到一个错误
com.google.gson.JsonPrimitive无法强制转换为com.google.gson.JsonObject
你能告诉我如何摆脱这个错误..
我们的应用程序工作正常,在尝试创建会话时,opentok突然抛出一个奇怪的异常。
您能否建议我们,必须采取哪些措施来避免这种异常?
异常详细信息如下:
Caused by: com.opentok.exception.OpenTokException:
org.xml.sax.SAXParseException; lineNumber: 6; columnNumber: 3; The element type "hr" must be terminated by the matching end-tag "</hr>". at
com.opentok.util.TokBoxXML.<init>(TokBoxXML.java:27) at
com.opentok.api.OpenTokSDK.do_request(OpenTokSDK.java:201) at
com.opentok.api.OpenTokSDK.create_session(OpenTokSDK.java:182) at
com.opentok.api.OpenTokSDK.create_session(OpenTokSDK.java:150) at
com.opentok.api.OpenTokSDK$create_session.call(Unknown Source) at
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42) at
com.opentok.api.OpenTokSDK$create_session.call(Unknown Source)
Run Code Online (Sandbox Code Playgroud)
提前致谢。
我正在使用Android Studio.我在我的应用程序中使用e-POS-Print.jar.每当我运行代码时,我都会收到此错误:
java.lang.ExceptionInInitializerError
at com.stc.printer.MyActivity.onCreate(MyActivity.java:48)
at android.app.Activity.performCreate(Activity.java:5163)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2061)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
at android.app.ActivityThread.access$600(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4895)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.UnsatisfiedLinkError: Couldn't load eposprint: findLibrary returned null
at java.lang.Runtime.loadLibrary(Runtime.java:365)
at java.lang.System.loadLibrary(System.java:535)
at com.epson.eposprint.Print.<clinit>(Print.java:18)
at com.stc.printer.MyActivity.onCreate(MyActivity.java:48)
Run Code Online (Sandbox Code Playgroud)
我的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
System.out.println("started");
printerName = getString(R.string.printername_t81ii);
language = Builder.MODEL_SOUTHASIA;
//bellow is line no. 48
Print newPrinter = new Print(getApplicationContext());
try{
newPrinter.openPrinter(deviceType, …Run Code Online (Sandbox Code Playgroud) java java-native-interface android shared-libraries android-ndk